├── GUI_Program
├── .DS_Store
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── bin
│ ├── .DS_Store
│ └── p
│ │ ├── Listener.class
│ │ ├── MyFrame.class
│ │ └── SSMain.class
├── output
└── src
│ ├── .DS_Store
│ └── p
│ ├── .DS_Store
│ ├── Listener.java
│ └── SSMain.java
├── HeaderFiles
├── .DS_Store
├── langFunctions.h
└── validators.h
├── LICENSE
├── README.md
├── lex.yy.c
├── output
├── sample
├── semantics.l
├── syntax2.y
├── y.tab.c
└── y.tab.h
/GUI_Program/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/.DS_Store
--------------------------------------------------------------------------------
/GUI_Program/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/GUI_Program/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | SystemSoftware_2
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/GUI_Program/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.6
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.6
12 |
--------------------------------------------------------------------------------
/GUI_Program/bin/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/bin/.DS_Store
--------------------------------------------------------------------------------
/GUI_Program/bin/p/Listener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/bin/p/Listener.class
--------------------------------------------------------------------------------
/GUI_Program/bin/p/MyFrame.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/bin/p/MyFrame.class
--------------------------------------------------------------------------------
/GUI_Program/bin/p/SSMain.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/bin/p/SSMain.class
--------------------------------------------------------------------------------
/GUI_Program/output:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/output
--------------------------------------------------------------------------------
/GUI_Program/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/src/.DS_Store
--------------------------------------------------------------------------------
/GUI_Program/src/p/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/GUI_Program/src/p/.DS_Store
--------------------------------------------------------------------------------
/GUI_Program/src/p/Listener.java:
--------------------------------------------------------------------------------
1 | package p;
2 |
3 | import java.awt.Color;
4 | import java.awt.event.MouseAdapter;
5 | import java.awt.event.MouseEvent;
6 | import java.io.BufferedReader;
7 | import java.io.File;
8 | import java.io.IOException;
9 | import java.io.InputStreamReader;
10 |
11 | import javax.swing.BorderFactory;
12 | import javax.swing.JButton;
13 | import javax.swing.JComponent;
14 | import javax.swing.JFileChooser;
15 | import javax.swing.JLabel;
16 | import javax.swing.JPanel;
17 | import javax.swing.JScrollPane;
18 |
19 | public class Listener extends MouseAdapter{
20 | JButton button;
21 | JLabel fileName,message;
22 | JPanel messagePanel;
23 | JScrollPane scrollPane;
24 |
25 | Listener(JButton button,JLabel fileName, JLabel message, JPanel messagePanel, JScrollPane scrollPane){
26 | this.button = button;
27 | this.fileName = fileName;
28 | this.message = message;
29 | this.messagePanel = messagePanel;
30 | this.scrollPane = scrollPane;
31 | }
32 |
33 | @Override
34 | public void mouseClicked(MouseEvent e){
35 | JFileChooser chooser = new JFileChooser();
36 | chooser.setDialogTitle("Load which file");
37 | int result = chooser.showOpenDialog(null);
38 | if (result == JFileChooser.APPROVE_OPTION) {
39 | File file = chooser.getSelectedFile();
40 | fileName.setText(" File chosen : " + file.getAbsolutePath());
41 | fileName.setAlignmentX(JComponent.CENTER_ALIGNMENT);
42 |
43 | /*
44 | * To re-center the label once the File has been chosen.
45 | * Otherwise, the entire program will un-align.
46 | */
47 | try {
48 |
49 | Runtime rt = Runtime.getRuntime();
50 | System.out.println("PATH : " + file.getPath());
51 | //Process proc = rt.exec(new String[] {"bash","-c",".././output <" + file.getAbsolutePath()});
52 | Process proc = rt.exec(new String[] {"bash","-c","/Users/Ajay/Documents/MY\\ JAVA\\ PROGRAMS/SystemSoftware_2/output <" + file.getAbsolutePath()});
53 | BufferedReader stdInput = new BufferedReader(new
54 | InputStreamReader(proc.getInputStream()));
55 |
56 | BufferedReader stdError = new BufferedReader(new
57 | InputStreamReader(proc.getErrorStream()));
58 |
59 | // read the output from the command
60 | System.out.println("Here is the standard output of the command:\n");
61 | String s = null;
62 | int i=0;
63 | message.setText("");
64 | while ((s = stdInput.readLine()) != null) {
65 |
66 | message.setText(message.getText() + "
" + s);
67 | System.out.println("LINE " + i + " : " + s);
68 | i++;
69 |
70 | }
71 |
72 | // read any errors from the attempted command
73 | i=0;
74 | System.out.println("Here is the standard error of the command (if any):\n");
75 | while ((s = stdError.readLine()) != null) {
76 | message.setText(message.getText() + "
" + s);
77 | System.out.println("LINE " + i + " : " + s);
78 | i++;
79 | }
80 |
81 | message.setText(message.getText() + "");
82 | setBorderColor();
83 | stdInput.close();
84 | stdError.close();
85 |
86 |
87 | } catch (IOException e1) {
88 | e1.printStackTrace();
89 | }
90 | }
91 | }
92 |
93 | void setBorderColor(){
94 | if(!message.getText().toLowerCase().contains("no errors")){
95 | message.setForeground(Color.RED);
96 | scrollPane.setBorder(BorderFactory.createLineBorder(Color.RED));
97 | }else{
98 | message.setForeground(Color.decode("#339966"));
99 | scrollPane.setBorder(BorderFactory.createLineBorder(Color.GREEN));
100 | }
101 | }
102 |
103 | @Override
104 | public void mouseEntered(MouseEvent e){
105 | button.setBackground(Color.decode("#8F92D9"));
106 | button.setForeground(Color.decode("#FFFFFF"));
107 | }
108 |
109 | @Override
110 | public void mouseExited(MouseEvent e){
111 | button.setBackground(Color.decode("#D7AE8F"));
112 | button.setForeground(Color.decode("#000000"));
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/GUI_Program/src/p/SSMain.java:
--------------------------------------------------------------------------------
1 |
2 | package p;
3 |
4 | import java.awt.Color;
5 | import java.awt.FlowLayout;
6 | import java.awt.Insets;
7 |
8 | import javax.swing.Box;
9 | import javax.swing.BoxLayout;
10 | import javax.swing.JButton;
11 | import javax.swing.JComponent;
12 | import javax.swing.JFrame;
13 | import javax.swing.JLabel;
14 | import javax.swing.JPanel;
15 | import javax.swing.JScrollPane;
16 |
17 | import javax.swing.border.EmptyBorder;
18 |
19 | class MyFrame extends JFrame{
20 |
21 | JPanel panel,messagePanel;
22 | JScrollPane scrollPane;
23 | JLabel heading;
24 | JButton fileChoose;
25 | JLabel fileName,message;
26 |
27 |
28 | MyFrame(){
29 | setSize(500,500);
30 | init();
31 | createGUI();
32 | setVisible(true);
33 | setDefaultCloseOperation(EXIT_ON_CLOSE);
34 | }
35 |
36 | void init(){
37 | fileChoose = new JButton("Choose File");
38 | panel = new JPanel();
39 | messagePanel = new JPanel();
40 | fileName = new JLabel();
41 | message = new JLabel();
42 | heading = new JLabel();
43 | scrollPane = new JScrollPane(messagePanel);
44 |
45 | }
46 |
47 | void createGUI(){
48 |
49 | panel.setBackground(Color.decode("#DEB877"));
50 | panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
51 | panel.setBorder(new EmptyBorder(30, 30, 60, 30));
52 |
53 | heading.setText("DECLARATION PROCESSOR FOR C");
54 | heading.setFont(new java.awt.Font("Courier", java.awt.Font.BOLD,20));
55 | heading.setAlignmentX(JComponent.CENTER_ALIGNMENT);
56 |
57 | fileChoose.setMargin(new Insets(10,10,10,10));
58 | fileChoose.setBackground(Color.decode("#D7AE8F"));
59 | fileChoose.setForeground(Color.decode("#000000"));
60 | fileChoose.setContentAreaFilled(false) ;
61 | fileChoose.setBorderPainted(false);
62 | fileChoose.setOpaque(true);
63 | fileChoose.setAlignmentX(JComponent.CENTER_ALIGNMENT);
64 |
65 | fileName.setText(" File chosen : ");
66 | fileName.setAlignmentX(JComponent.CENTER_ALIGNMENT);
67 |
68 | messagePanel.setLayout(new FlowLayout());
69 | messagePanel.setBackground(Color.WHITE);
70 | messagePanel.add(message);
71 |
72 | panel.add(heading);
73 | panel.add(Box.createVerticalStrut(20));
74 | panel.add(fileChoose);
75 | panel.add(Box.createVerticalStrut(20));
76 | panel.add(fileName);
77 | panel.add(Box.createVerticalStrut(20));
78 | panel.add(scrollPane);
79 | panel.add(Box.createVerticalStrut(20));
80 | add(panel);
81 |
82 | fileChoose.addMouseListener(new Listener(fileChoose,fileName,message,messagePanel,scrollPane));
83 | }
84 | }
85 |
86 | public class SSMain {
87 | public static void main(String[] args) {
88 | new MyFrame();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/HeaderFiles/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/HeaderFiles/.DS_Store
--------------------------------------------------------------------------------
/HeaderFiles/langFunctions.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | char Data_Type[50];
5 |
6 | int noOfIdentifiers = 0;
7 |
8 | struct IdentifierStructure
9 | {
10 | char* value;
11 | char* data_type;
12 | }identifiers[20];
13 |
14 | char* IdentifierArray[20]; //Not using this anywhere. :/
15 | extern int yylineno;
16 | extern char* yytext; //Not using this anywhere. :/
17 |
18 | //For development only
19 | void showIdentifiers(){
20 | int i;
21 | for(i=0;i
2 | // because we need to use the built-in function strcmp(), which is in string.h header file
3 | #include "../y.tab.h" //
4 | // '..' indicates that y.tab.h is in the parent directory.
5 | //We need to include y.tab.h because we want to include "number" from the y.tab.h
6 |
7 | extern int strcmp(const char*,const char*);
8 |
9 | extern char Data_Type[50];
10 | // 'extern' means that 'Data_Type[50]' is actually declared in another file (langFunctions.h)
11 |
12 |
13 | /*
14 | This function checks if the data type "givenDatatype", which is passed in as the parameter, is the data type of the identifier (from the yacc file).
15 | if valid, return 1,
16 | if invalid, return 0
17 | */
18 | int isValidAssignment(char* givenDatatype){
19 | int i=0;
20 |
21 | if(strcmp(givenDatatype,Data_Type) != 0){
22 | return 0;
23 | }
24 | return 1;
25 | }
26 |
27 | /*
28 | This function converts INTEGER to ASCII
29 | The equivalent ascii value of "number" is stored in the character array "buffer" and is returned .
30 | snprintf() accomplishes this task
31 | */
32 | char* itoa(int number){
33 | static char buffer[33];
34 | snprintf(buffer, sizeof(buffer), "%d", number);
35 | return buffer;
36 | }
37 |
38 |
39 |
40 | /*
41 | This function converts FLOATING POINT NUMBER to ASCII
42 | The equivalent ascii value of "number" is stored in the character array "buffer" and is returned .
43 | snprintf() accomplishes this task
44 | */
45 | char* ftoa(float number){
46 | static char buffer[33];
47 | snprintf(buffer, sizeof(buffer), "%f", number);
48 | return buffer;
49 | }
50 |
51 |
52 | /*
53 | This function converts CHARACTER to ASCII
54 | The equivalent ascii value of "number" is stored in the character array "buffer" and is returned .
55 | snprintf() accomplishes this task
56 | */
57 | char* ctoa(char number){
58 | static char buffer[33];
59 | snprintf(buffer, sizeof(buffer), "%c", number);
60 | return buffer;
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Ajay Halthor
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # interpreter
2 | Interpreter for the Declaration Section of a C program
3 |
4 | We’ll use 2 language tools: Lex and Yacc (or flex and bison) to accomplish this.
5 |
6 | ## The LEX file
7 |
8 | The lex file has 3 main parts, separated by “double percentage signs”. The first part is a list of harder files and function definitions encapsulated in “percentage-curly braces”. The second part has the list of acceptable tokens and the final is for some C user defined functions.
9 |
10 | `y.tab.h` is generated by Yacc and it defines the list of tokens that we mention here.
11 |
12 | In the next section, we start by defining datatype tokens. Although struct can be considered a datatype token, we considered it as a `STRUCT` token separately because of its unique syntax. Then we define the single character tokens. We also define character, integer & floating point values. From here, we start getting more generic to Array_identifiers, identifiers and strings. When a linefeed character (`\n` in this case) is encountered, `yylineno` is incremented. `yylineno` keeps track of the line number in the input C file. We just ignore any other token.
13 |
14 | How this works is that. The token encountered is stored in a variable called `yytext`. It is compared with these list of acceptable token formats from top to bottom. The first time it finds a match, the corresponding code on the right hand side is executed. If,say we encounter the token “int”, this is stored in `yytext` and matched up against the token list. Since it is present in the beginning itself, the corresponding C code in curly braces is executed. Here, “int” is stored in `yylval`. `yylval` is required to pass tokens recognized from the Lexer to the parser. So, this variable `yylval` is considered the bridge between the two. You only need to pass values through `yylval` if you plan to use the value in the parser. For other tokens, you don't need to worry about it. And this “dataType” could have been anything else, like “string_value” or “blah_blah”. I used dataType because it just makes sense to me.
15 |
16 | In the 3rd and final section, we have a implemented a few functions. `yywrap` is called when the End of input file is reached. It returns 1 to signal the end of input, which is true for our case as we input 1 file at a time. `yyerror` is invoked when an invalid token or sequence is encountered. It takes in the error string as input and we display the line number and error message just like you would see in a compiler. I also defined an `InvalidToken` function to catch stray tokens in case they don't invoke `yyerror`. This may not be the most efficient way to define to tokens or write function, but its not half bad.
17 |
18 |
19 | ## The YACC file
20 |
21 | Like the lex file, this also consists of 3 sections. The first part is a list of harder files and function definitions encapsulated in “percentage-curly braces”. After that, we declare a number of datatypes and functions. If “extern” precedes their declaration, then those variables or those functions are actually defined externally. that is, not in this file. In between the first and second sections, we define the nature of the error message generated by YACC.
22 |
23 | - `%union` allows us to define the members of yylval. yylval is actually of type “union”.
24 |
25 | - `%token` is used to define the tokens passed from the lex file. If the value of the token is passed, be sure to indicate the type in angular brackets .
26 |
27 | - `%type` is used to define the symbols used below that are not tokens passed from the lex file. They are a combination of those tokens.
28 |
29 | Everything mentioned here was between the 1st and 2nd section. Now lets take a look at the 2nd section, which is the meat of this file, if not the entire application. It is here that we define the Grammar for our language, which is C in our case.
30 |
31 | Since we are dealing with declaration statements, it makes sense to make this “Declaration” the root of the tree. Every statement in our input C files must be a declaration statement of one of the following forms mentioned. If the statement does not conform to any of these froms, then `yyerror` is invoked and this angular bracket stops execution.
32 |
33 | Since it stops checking for errors after the first is encountered, I guess its more like an interpreter than a compiler.
34 |
35 | In the third section, we have a main function which is the starting point of exectution. Here, we call `yyparse()` which initiates all the tokenismg and parsing discussed until now. Its an amazing function. Since the program stops on encountering an error, yyparse will only return if no errors are found. So its safe to say that if a program reaches this point, there are no errors in the input C file.
36 |
37 | ## Header Files
38 |
39 | ### langFunctions.h
40 |
41 | Data_Type : character array that holds the data_type for the current declaration statement.
42 | noOfIdentifiers : number of identifiers in the input file.
43 |
44 | clearBuffers() : to clear the value of the datatype stored.
45 | storeDataType() : to store the datatype of the current declaration statement.
46 | retrieveDataType(): Created to make things look uniform.
47 | isDuplicate() : checks if the newly encountered identifier has already been declared before.
48 | extractIdentifier() : extracts the name of the array.
49 | storeIdentifier() : add the encountered identifier to the list of identifiers.
50 | AssignmentError() is called in case an invalid assignment is made
51 | DuplicateIdentifierError() is called if the isDuplicate() function returns True in the yacc file.
52 |
53 | ### validators.h
54 |
55 | isValidAssignment() : checks if the datatype which we pass in from the later part of the yacc file is the same as the current datatype of the identifier.
56 |
57 | itoa, ftoa and ctoa are used to convert integers, floating point numbers and characters into ascii type.
58 |
59 |
60 | ## Generate output without GUI
61 |
62 | To execute this code, Go to your terminal, enter your working directory and type 4 commands.
63 | ```
64 | $ yacc -d syntax2.y
65 | $ lex semantics.l
66 | $ cc lex.yy.c y.tab.c -o output
67 | $ ./output < sample
68 | ```
69 |
70 | ## The Java GUI
71 |
72 | This project will have 3 classes:
73 | - `SSMain` — that contains the main function
74 | - `MyFrame` — creates the window frame, the file chooser and the rest of the UI
75 | - `Listener`- which listens to mouse events and perform the execution of the “output” file
76 |
77 | Take the output file generated from the compilation of `lex.yy.c` and `y.tab.c` and put it in our project directory, on the sample level as the source folder. Before I move any further, I’ll just gloss over the 2 main classes here : `MyFrame` and `Listener`.
78 |
79 | Myframe extends the JFrame class and inherits its properties and methods.
80 |
81 | - JPanel to give a nice background to the app.
82 | - JScrollPane will be used to display the error message.
83 | - JLabel is used to display text. We will use it to display the full path of the sample file chosen, on the botton and other places where text is required.
84 | - JButton is used to create the file chooser button.
85 |
86 | In our constructor, we set the initial size of the window to be 500 by 500 pixels. We then instantiate all the elements I just discussed. In the `createGUI()` method , the components are added and positioned on the screen. At the end of the method, we add a mouse listener for the `JButton` we created. The “listener” is actually the `Listener` Class, which I’ll explain now.
87 |
88 | Listener handles 3 major mouse events.
89 | 1. a Mouse Click event
90 | 2. a Mouse Enter event
91 | 3. a mouse exit event
92 |
93 | When the “Choose File” button is clicked, a file chooser opens up where the user selects their sample file. Once the file is chosen, we execute the typical output command that we use in the terminal in the last video . The response is stored in the message variable and displayed on the screen for the user.
94 |
95 | `setBorderColor()` method creates a red border and text if an error is displayed. Otherwise, the text and border color are both green. The other 2 mouse events are just used to give a hover effect on the “choose” button for a nice UI. And that all code for the GUI. Now, lets run thing with 4 sample files.
96 |
97 |
98 | ### Run Program
99 |
100 | If you want to execute this program on command line, go to your terminal and enter your project directory. and enter the `src` folder. Since our main class SSMain is in the package p, we compile it with the command
101 | ```
102 | $ javac p/SSMain.java
103 | ```
104 |
105 | This will generate the corresponding class files. Now, execute it with the command
106 | ```
107 | $ java p.SSMain
108 | ```
109 |
110 | And clearly, everything works the same even without eclipse. So, this will certainly come in useful for people who think eclipse, netbeans or any other java specific IDE is too slow.
111 |
--------------------------------------------------------------------------------
/lex.yy.c:
--------------------------------------------------------------------------------
1 |
2 | #line 3 "lex.yy.c"
3 |
4 | #define YY_INT_ALIGNED short int
5 |
6 | /* A lexical scanner generated by flex */
7 |
8 | #define FLEX_SCANNER
9 | #define YY_FLEX_MAJOR_VERSION 2
10 | #define YY_FLEX_MINOR_VERSION 5
11 | #define YY_FLEX_SUBMINOR_VERSION 35
12 | #if YY_FLEX_SUBMINOR_VERSION > 0
13 | #define FLEX_BETA
14 | #endif
15 |
16 | /* First, we deal with platform-specific or compiler-specific issues. */
17 |
18 | /* begin standard C headers. */
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | /* end standard C headers. */
25 |
26 | /* flex integer type definitions */
27 |
28 | #ifndef FLEXINT_H
29 | #define FLEXINT_H
30 |
31 | /* C99 systems have . Non-C99 systems may or may not. */
32 |
33 | #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
34 |
35 | /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
36 | * if you want the limit (max/min) macros for int types.
37 | */
38 | #ifndef __STDC_LIMIT_MACROS
39 | #define __STDC_LIMIT_MACROS 1
40 | #endif
41 |
42 | #include
43 | typedef int8_t flex_int8_t;
44 | typedef uint8_t flex_uint8_t;
45 | typedef int16_t flex_int16_t;
46 | typedef uint16_t flex_uint16_t;
47 | typedef int32_t flex_int32_t;
48 | typedef uint32_t flex_uint32_t;
49 | typedef uint64_t flex_uint64_t;
50 | #else
51 | typedef signed char flex_int8_t;
52 | typedef short int flex_int16_t;
53 | typedef int flex_int32_t;
54 | typedef unsigned char flex_uint8_t;
55 | typedef unsigned short int flex_uint16_t;
56 | typedef unsigned int flex_uint32_t;
57 | #endif /* ! C99 */
58 |
59 | /* Limits of integral types. */
60 | #ifndef INT8_MIN
61 | #define INT8_MIN (-128)
62 | #endif
63 | #ifndef INT16_MIN
64 | #define INT16_MIN (-32767-1)
65 | #endif
66 | #ifndef INT32_MIN
67 | #define INT32_MIN (-2147483647-1)
68 | #endif
69 | #ifndef INT8_MAX
70 | #define INT8_MAX (127)
71 | #endif
72 | #ifndef INT16_MAX
73 | #define INT16_MAX (32767)
74 | #endif
75 | #ifndef INT32_MAX
76 | #define INT32_MAX (2147483647)
77 | #endif
78 | #ifndef UINT8_MAX
79 | #define UINT8_MAX (255U)
80 | #endif
81 | #ifndef UINT16_MAX
82 | #define UINT16_MAX (65535U)
83 | #endif
84 | #ifndef UINT32_MAX
85 | #define UINT32_MAX (4294967295U)
86 | #endif
87 |
88 | #endif /* ! FLEXINT_H */
89 |
90 | #ifdef __cplusplus
91 |
92 | /* The "const" storage-class-modifier is valid. */
93 | #define YY_USE_CONST
94 |
95 | #else /* ! __cplusplus */
96 |
97 | /* C99 requires __STDC__ to be defined as 1. */
98 | #if defined (__STDC__)
99 |
100 | #define YY_USE_CONST
101 |
102 | #endif /* defined (__STDC__) */
103 | #endif /* ! __cplusplus */
104 |
105 | #ifdef YY_USE_CONST
106 | #define yyconst const
107 | #else
108 | #define yyconst
109 | #endif
110 |
111 | /* Returned upon end-of-file. */
112 | #define YY_NULL 0
113 |
114 | /* Promotes a possibly negative, possibly signed char to an unsigned
115 | * integer for use as an array index. If the signed char is negative,
116 | * we want to instead treat it as an 8-bit unsigned char, hence the
117 | * double cast.
118 | */
119 | #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
120 |
121 | /* Enter a start condition. This macro really ought to take a parameter,
122 | * but we do it the disgusting crufty way forced on us by the ()-less
123 | * definition of BEGIN.
124 | */
125 | #define BEGIN (yy_start) = 1 + 2 *
126 |
127 | /* Translate the current start state into a value that can be later handed
128 | * to BEGIN to return to the state. The YYSTATE alias is for lex
129 | * compatibility.
130 | */
131 | #define YY_START (((yy_start) - 1) / 2)
132 | #define YYSTATE YY_START
133 |
134 | /* Action number for EOF rule of a given start state. */
135 | #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
136 |
137 | /* Special action meaning "start processing a new file". */
138 | #define YY_NEW_FILE yyrestart(yyin )
139 |
140 | #define YY_END_OF_BUFFER_CHAR 0
141 |
142 | /* Size of default input buffer. */
143 | #ifndef YY_BUF_SIZE
144 | #define YY_BUF_SIZE 16384
145 | #endif
146 |
147 | /* The state buf must be large enough to hold one state per character in the main buffer.
148 | */
149 | #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
150 |
151 | #ifndef YY_TYPEDEF_YY_BUFFER_STATE
152 | #define YY_TYPEDEF_YY_BUFFER_STATE
153 | typedef struct yy_buffer_state *YY_BUFFER_STATE;
154 | #endif
155 |
156 | #ifndef YY_TYPEDEF_YY_SIZE_T
157 | #define YY_TYPEDEF_YY_SIZE_T
158 | typedef size_t yy_size_t;
159 | #endif
160 |
161 | extern yy_size_t yyleng;
162 |
163 | extern FILE *yyin, *yyout;
164 |
165 | #define EOB_ACT_CONTINUE_SCAN 0
166 | #define EOB_ACT_END_OF_FILE 1
167 | #define EOB_ACT_LAST_MATCH 2
168 |
169 | #define YY_LESS_LINENO(n)
170 |
171 | /* Return all but the first "n" matched characters back to the input stream. */
172 | #define yyless(n) \
173 | do \
174 | { \
175 | /* Undo effects of setting up yytext. */ \
176 | int yyless_macro_arg = (n); \
177 | YY_LESS_LINENO(yyless_macro_arg);\
178 | *yy_cp = (yy_hold_char); \
179 | YY_RESTORE_YY_MORE_OFFSET \
180 | (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
181 | YY_DO_BEFORE_ACTION; /* set up yytext again */ \
182 | } \
183 | while ( 0 )
184 |
185 | #define unput(c) yyunput( c, (yytext_ptr) )
186 |
187 | #ifndef YY_STRUCT_YY_BUFFER_STATE
188 | #define YY_STRUCT_YY_BUFFER_STATE
189 | struct yy_buffer_state
190 | {
191 | FILE *yy_input_file;
192 |
193 | char *yy_ch_buf; /* input buffer */
194 | char *yy_buf_pos; /* current position in input buffer */
195 |
196 | /* Size of input buffer in bytes, not including room for EOB
197 | * characters.
198 | */
199 | yy_size_t yy_buf_size;
200 |
201 | /* Number of characters read into yy_ch_buf, not including EOB
202 | * characters.
203 | */
204 | yy_size_t yy_n_chars;
205 |
206 | /* Whether we "own" the buffer - i.e., we know we created it,
207 | * and can realloc() it to grow it, and should free() it to
208 | * delete it.
209 | */
210 | int yy_is_our_buffer;
211 |
212 | /* Whether this is an "interactive" input source; if so, and
213 | * if we're using stdio for input, then we want to use getc()
214 | * instead of fread(), to make sure we stop fetching input after
215 | * each newline.
216 | */
217 | int yy_is_interactive;
218 |
219 | /* Whether we're considered to be at the beginning of a line.
220 | * If so, '^' rules will be active on the next match, otherwise
221 | * not.
222 | */
223 | int yy_at_bol;
224 |
225 | int yy_bs_lineno; /**< The line count. */
226 | int yy_bs_column; /**< The column count. */
227 |
228 | /* Whether to try to fill the input buffer when we reach the
229 | * end of it.
230 | */
231 | int yy_fill_buffer;
232 |
233 | int yy_buffer_status;
234 |
235 | #define YY_BUFFER_NEW 0
236 | #define YY_BUFFER_NORMAL 1
237 | /* When an EOF's been seen but there's still some text to process
238 | * then we mark the buffer as YY_EOF_PENDING, to indicate that we
239 | * shouldn't try reading from the input source any more. We might
240 | * still have a bunch of tokens to match, though, because of
241 | * possible backing-up.
242 | *
243 | * When we actually see the EOF, we change the status to "new"
244 | * (via yyrestart()), so that the user can continue scanning by
245 | * just pointing yyin at a new input file.
246 | */
247 | #define YY_BUFFER_EOF_PENDING 2
248 |
249 | };
250 | #endif /* !YY_STRUCT_YY_BUFFER_STATE */
251 |
252 | /* Stack of input buffers. */
253 | static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
254 | static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
255 | static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
256 |
257 | /* We provide macros for accessing buffer states in case in the
258 | * future we want to put the buffer states in a more general
259 | * "scanner state".
260 | *
261 | * Returns the top of the stack, or NULL.
262 | */
263 | #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
264 | ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
265 | : NULL)
266 |
267 | /* Same as previous macro, but useful when we know that the buffer stack is not
268 | * NULL or when we need an lvalue. For internal use only.
269 | */
270 | #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
271 |
272 | /* yy_hold_char holds the character lost when yytext is formed. */
273 | static char yy_hold_char;
274 | static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
275 | yy_size_t yyleng;
276 |
277 | /* Points to current character in buffer. */
278 | static char *yy_c_buf_p = (char *) 0;
279 | static int yy_init = 0; /* whether we need to initialize */
280 | static int yy_start = 0; /* start state number */
281 |
282 | /* Flag which is used to allow yywrap()'s to do buffer switches
283 | * instead of setting up a fresh yyin. A bit of a hack ...
284 | */
285 | static int yy_did_buffer_switch_on_eof;
286 |
287 | void yyrestart (FILE *input_file );
288 | void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer );
289 | YY_BUFFER_STATE yy_create_buffer (FILE *file,int size );
290 | void yy_delete_buffer (YY_BUFFER_STATE b );
291 | void yy_flush_buffer (YY_BUFFER_STATE b );
292 | void yypush_buffer_state (YY_BUFFER_STATE new_buffer );
293 | void yypop_buffer_state (void );
294 |
295 | static void yyensure_buffer_stack (void );
296 | static void yy_load_buffer_state (void );
297 | static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file );
298 |
299 | #define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER )
300 |
301 | YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size );
302 | YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str );
303 | YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len );
304 |
305 | void *yyalloc (yy_size_t );
306 | void *yyrealloc (void *,yy_size_t );
307 | void yyfree (void * );
308 |
309 | #define yy_new_buffer yy_create_buffer
310 |
311 | #define yy_set_interactive(is_interactive) \
312 | { \
313 | if ( ! YY_CURRENT_BUFFER ){ \
314 | yyensure_buffer_stack (); \
315 | YY_CURRENT_BUFFER_LVALUE = \
316 | yy_create_buffer(yyin,YY_BUF_SIZE ); \
317 | } \
318 | YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
319 | }
320 |
321 | #define yy_set_bol(at_bol) \
322 | { \
323 | if ( ! YY_CURRENT_BUFFER ){\
324 | yyensure_buffer_stack (); \
325 | YY_CURRENT_BUFFER_LVALUE = \
326 | yy_create_buffer(yyin,YY_BUF_SIZE ); \
327 | } \
328 | YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
329 | }
330 |
331 | #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
332 |
333 | /* Begin user sect3 */
334 |
335 | typedef unsigned char YY_CHAR;
336 |
337 | FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
338 |
339 | typedef int yy_state_type;
340 |
341 | extern int yylineno;
342 |
343 | int yylineno = 1;
344 |
345 | extern char *yytext;
346 | #define yytext_ptr yytext
347 |
348 | static yy_state_type yy_get_previous_state (void );
349 | static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
350 | static int yy_get_next_buffer (void );
351 | static void yy_fatal_error (yyconst char msg[] );
352 |
353 | /* Done after the current pattern has been matched and before the
354 | * corresponding action - sets up yytext.
355 | */
356 | #define YY_DO_BEFORE_ACTION \
357 | (yytext_ptr) = yy_bp; \
358 | yyleng = (yy_size_t) (yy_cp - yy_bp); \
359 | (yy_hold_char) = *yy_cp; \
360 | *yy_cp = '\0'; \
361 | (yy_c_buf_p) = yy_cp;
362 |
363 | #define YY_NUM_RULES 31
364 | #define YY_END_OF_BUFFER 32
365 | /* This struct is not used in this scanner,
366 | but its presence is necessary. */
367 | struct yy_trans_info
368 | {
369 | flex_int32_t yy_verify;
370 | flex_int32_t yy_nxt;
371 | };
372 | static yyconst flex_int16_t yy_accept[80] =
373 | { 0,
374 | 0, 0, 32, 30, 29, 28, 30, 12, 16, 17,
375 | 30, 13, 30, 23, 14, 15, 26, 20, 21, 26,
376 | 26, 26, 26, 26, 26, 18, 19, 0, 27, 0,
377 | 0, 0, 23, 24, 26, 0, 26, 26, 26, 26,
378 | 26, 26, 0, 27, 0, 22, 0, 26, 26, 2,
379 | 26, 26, 26, 25, 3, 26, 8, 26, 26, 1,
380 | 9, 4, 26, 26, 7, 10, 11, 26, 26, 26,
381 | 0, 0, 0, 0, 0, 0, 5, 6, 0
382 | } ;
383 |
384 | static yyconst flex_int32_t yy_ec[256] =
385 | { 0,
386 | 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
387 | 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
388 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
389 | 1, 4, 1, 5, 1, 1, 1, 1, 6, 7,
390 | 8, 9, 10, 11, 10, 12, 1, 13, 13, 13,
391 | 13, 13, 13, 13, 13, 13, 13, 1, 14, 1,
392 | 15, 1, 1, 1, 16, 16, 16, 16, 16, 16,
393 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
394 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
395 | 17, 18, 19, 1, 20, 1, 21, 16, 22, 23,
396 |
397 | 24, 25, 26, 27, 28, 16, 16, 29, 16, 30,
398 | 31, 16, 16, 32, 33, 34, 35, 36, 16, 16,
399 | 16, 16, 37, 1, 38, 1, 1, 1, 1, 1,
400 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
401 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
402 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
403 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
404 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
405 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
406 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
407 |
408 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
409 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
410 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
411 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
412 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
413 | 1, 1, 1, 1, 1
414 | } ;
415 |
416 | static yyconst flex_int32_t yy_meta[39] =
417 | { 0,
418 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
419 | 1, 1, 2, 1, 1, 3, 2, 1, 1, 2,
420 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
421 | 3, 3, 3, 3, 3, 3, 1, 1
422 | } ;
423 |
424 | static yyconst flex_int16_t yy_base[84] =
425 | { 0,
426 | 0, 0, 144, 145, 145, 145, 34, 0, 145, 145,
427 | 28, 145, 130, 30, 145, 145, 125, 145, 145, 27,
428 | 28, 29, 30, 31, 32, 145, 145, 48, 145, 53,
429 | 135, 127, 38, 126, 121, 124, 48, 43, 38, 45,
430 | 50, 51, 68, 70, 73, 145, 68, 53, 63, 73,
431 | 72, 75, 76, 119, 85, 78, 145, 79, 80, 91,
432 | 145, 96, 81, 87, 145, 145, 118, 92, 97, 106,
433 | 96, 107, 103, 101, 87, 87, 145, 145, 145, 124,
434 | 108, 126, 129
435 | } ;
436 |
437 | static yyconst flex_int16_t yy_def[84] =
438 | { 0,
439 | 79, 1, 79, 79, 79, 79, 80, 81, 79, 79,
440 | 79, 79, 79, 79, 79, 79, 82, 79, 79, 82,
441 | 82, 82, 82, 82, 82, 79, 79, 80, 79, 83,
442 | 79, 79, 79, 79, 82, 79, 82, 82, 82, 82,
443 | 82, 82, 80, 80, 83, 79, 79, 82, 82, 82,
444 | 82, 82, 82, 79, 82, 82, 79, 82, 82, 82,
445 | 79, 82, 82, 82, 79, 79, 82, 82, 82, 82,
446 | 79, 79, 79, 79, 79, 79, 79, 79, 0, 79,
447 | 79, 79, 79
448 | } ;
449 |
450 | static yyconst flex_int16_t yy_nxt[184] =
451 | { 0,
452 | 4, 5, 6, 5, 7, 8, 9, 10, 4, 11,
453 | 12, 13, 14, 15, 16, 17, 18, 4, 19, 4,
454 | 17, 20, 17, 17, 21, 17, 17, 22, 17, 17,
455 | 17, 17, 23, 17, 24, 25, 26, 27, 29, 32,
456 | 33, 32, 33, 36, 36, 36, 36, 36, 36, 32,
457 | 33, 30, 29, 37, 36, 28, 38, 44, 39, 36,
458 | 41, 36, 42, 40, 36, 30, 36, 36, 48, 36,
459 | 45, 50, 29, 49, 29, 28, 51, 44, 53, 36,
460 | 47, 57, 52, 56, 55, 30, 54, 30, 36, 36,
461 | 45, 36, 36, 61, 36, 36, 36, 36, 60, 65,
462 |
463 | 63, 36, 59, 36, 66, 64, 58, 36, 36, 71,
464 | 31, 62, 36, 36, 67, 69, 68, 72, 78, 70,
465 | 77, 76, 36, 73, 28, 28, 28, 35, 35, 43,
466 | 43, 43, 75, 74, 36, 36, 47, 36, 34, 34,
467 | 46, 36, 34, 79, 3, 79, 79, 79, 79, 79,
468 | 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
469 | 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
470 | 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
471 | 79, 79, 79
472 | } ;
473 |
474 | static yyconst flex_int16_t yy_chk[184] =
475 | { 0,
476 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
477 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
478 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
479 | 1, 1, 1, 1, 1, 1, 1, 1, 7, 11,
480 | 11, 14, 14, 20, 21, 22, 23, 24, 25, 33,
481 | 33, 7, 28, 20, 39, 30, 21, 30, 22, 38,
482 | 24, 40, 25, 23, 37, 28, 41, 42, 37, 48,
483 | 30, 39, 43, 38, 44, 45, 40, 45, 42, 49,
484 | 47, 50, 41, 49, 48, 43, 47, 44, 51, 50,
485 | 45, 52, 53, 55, 56, 58, 59, 63, 53, 60,
486 |
487 | 58, 55, 52, 64, 62, 59, 51, 60, 68, 70,
488 | 81, 56, 62, 69, 63, 68, 64, 71, 76, 69,
489 | 75, 74, 70, 71, 80, 80, 80, 82, 82, 83,
490 | 83, 83, 73, 72, 67, 54, 36, 35, 34, 32,
491 | 31, 17, 13, 3, 79, 79, 79, 79, 79, 79,
492 | 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
493 | 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
494 | 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
495 | 79, 79, 79
496 | } ;
497 |
498 | static yy_state_type yy_last_accepting_state;
499 | static char *yy_last_accepting_cpos;
500 |
501 | extern int yy_flex_debug;
502 | int yy_flex_debug = 0;
503 |
504 | /* The intent behind this definition is that it'll catch
505 | * any uses of REJECT which flex missed.
506 | */
507 | #define REJECT reject_used_but_not_detected
508 | #define yymore() yymore_used_but_not_detected
509 | #define YY_MORE_ADJ 0
510 | #define YY_RESTORE_YY_MORE_OFFSET
511 | char *yytext;
512 | #line 1 "semantics.l"
513 | #line 2 "semantics.l"
514 | #include
515 | #include
516 | #include "y.tab.h"
517 | void extern yyerror(char*);
518 | void InvalidToken();
519 |
520 | #line 521 "lex.yy.c"
521 |
522 | #define INITIAL 0
523 |
524 | #ifndef YY_NO_UNISTD_H
525 | /* Special case for "unistd.h", since it is non-ANSI. We include it way
526 | * down here because we want the user's section 1 to have been scanned first.
527 | * The user has a chance to override it with an option.
528 | */
529 | #include
530 | #endif
531 |
532 | #ifndef YY_EXTRA_TYPE
533 | #define YY_EXTRA_TYPE void *
534 | #endif
535 |
536 | static int yy_init_globals (void );
537 |
538 | /* Accessor methods to globals.
539 | These are made visible to non-reentrant scanners for convenience. */
540 |
541 | int yylex_destroy (void );
542 |
543 | int yyget_debug (void );
544 |
545 | void yyset_debug (int debug_flag );
546 |
547 | YY_EXTRA_TYPE yyget_extra (void );
548 |
549 | void yyset_extra (YY_EXTRA_TYPE user_defined );
550 |
551 | FILE *yyget_in (void );
552 |
553 | void yyset_in (FILE * in_str );
554 |
555 | FILE *yyget_out (void );
556 |
557 | void yyset_out (FILE * out_str );
558 |
559 | yy_size_t yyget_leng (void );
560 |
561 | char *yyget_text (void );
562 |
563 | int yyget_lineno (void );
564 |
565 | void yyset_lineno (int line_number );
566 |
567 | /* Macros after this point can all be overridden by user definitions in
568 | * section 1.
569 | */
570 |
571 | #ifndef YY_SKIP_YYWRAP
572 | #ifdef __cplusplus
573 | extern "C" int yywrap (void );
574 | #else
575 | extern int yywrap (void );
576 | #endif
577 | #endif
578 |
579 | static void yyunput (int c,char *buf_ptr );
580 |
581 | #ifndef yytext_ptr
582 | static void yy_flex_strncpy (char *,yyconst char *,int );
583 | #endif
584 |
585 | #ifdef YY_NEED_STRLEN
586 | static int yy_flex_strlen (yyconst char * );
587 | #endif
588 |
589 | #ifndef YY_NO_INPUT
590 |
591 | #ifdef __cplusplus
592 | static int yyinput (void );
593 | #else
594 | static int input (void );
595 | #endif
596 |
597 | #endif
598 |
599 | /* Amount of stuff to slurp up with each read. */
600 | #ifndef YY_READ_BUF_SIZE
601 | #define YY_READ_BUF_SIZE 8192
602 | #endif
603 |
604 | /* Copy whatever the last rule matched to the standard output. */
605 | #ifndef ECHO
606 | /* This used to be an fputs(), but since the string might contain NUL's,
607 | * we now use fwrite().
608 | */
609 | #define ECHO fwrite( yytext, yyleng, 1, yyout )
610 | #endif
611 |
612 | /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
613 | * is returned in "result".
614 | */
615 | #ifndef YY_INPUT
616 | #define YY_INPUT(buf,result,max_size) \
617 | if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
618 | { \
619 | int c = '*'; \
620 | yy_size_t n; \
621 | for ( n = 0; n < max_size && \
622 | (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
623 | buf[n] = (char) c; \
624 | if ( c == '\n' ) \
625 | buf[n++] = (char) c; \
626 | if ( c == EOF && ferror( yyin ) ) \
627 | YY_FATAL_ERROR( "input in flex scanner failed" ); \
628 | result = n; \
629 | } \
630 | else \
631 | { \
632 | errno=0; \
633 | while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
634 | { \
635 | if( errno != EINTR) \
636 | { \
637 | YY_FATAL_ERROR( "input in flex scanner failed" ); \
638 | break; \
639 | } \
640 | errno=0; \
641 | clearerr(yyin); \
642 | } \
643 | }\
644 | \
645 |
646 | #endif
647 |
648 | /* No semi-colon after return; correct usage is to write "yyterminate();" -
649 | * we don't want an extra ';' after the "return" because that will cause
650 | * some compilers to complain about unreachable statements.
651 | */
652 | #ifndef yyterminate
653 | #define yyterminate() return YY_NULL
654 | #endif
655 |
656 | /* Number of entries by which start-condition stack grows. */
657 | #ifndef YY_START_STACK_INCR
658 | #define YY_START_STACK_INCR 25
659 | #endif
660 |
661 | /* Report a fatal error. */
662 | #ifndef YY_FATAL_ERROR
663 | #define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
664 | #endif
665 |
666 | /* end tables serialization structures and prototypes */
667 |
668 | /* Default declaration of generated scanner - a define so the user can
669 | * easily add parameters.
670 | */
671 | #ifndef YY_DECL
672 | #define YY_DECL_IS_OURS 1
673 |
674 | extern int yylex (void);
675 |
676 | #define YY_DECL int yylex (void)
677 | #endif /* !YY_DECL */
678 |
679 | /* Code executed at the beginning of each rule, after yytext and yyleng
680 | * have been set up.
681 | */
682 | #ifndef YY_USER_ACTION
683 | #define YY_USER_ACTION
684 | #endif
685 |
686 | /* Code executed at the end of each rule. */
687 | #ifndef YY_BREAK
688 | #define YY_BREAK break;
689 | #endif
690 |
691 | #define YY_RULE_SETUP \
692 | YY_USER_ACTION
693 |
694 | /** The main scanner function which does all the work.
695 | */
696 | YY_DECL
697 | {
698 | register yy_state_type yy_current_state;
699 | register char *yy_cp, *yy_bp;
700 | register int yy_act;
701 |
702 | #line 13 "semantics.l"
703 |
704 | #line 705 "lex.yy.c"
705 |
706 | if ( !(yy_init) )
707 | {
708 | (yy_init) = 1;
709 |
710 | #ifdef YY_USER_INIT
711 | YY_USER_INIT;
712 | #endif
713 |
714 | if ( ! (yy_start) )
715 | (yy_start) = 1; /* first start state */
716 |
717 | if ( ! yyin )
718 | yyin = stdin;
719 |
720 | if ( ! yyout )
721 | yyout = stdout;
722 |
723 | if ( ! YY_CURRENT_BUFFER ) {
724 | yyensure_buffer_stack ();
725 | YY_CURRENT_BUFFER_LVALUE =
726 | yy_create_buffer(yyin,YY_BUF_SIZE );
727 | }
728 |
729 | yy_load_buffer_state( );
730 | }
731 |
732 | while ( 1 ) /* loops until end-of-file is reached */
733 | {
734 | yy_cp = (yy_c_buf_p);
735 |
736 | /* Support of yytext. */
737 | *yy_cp = (yy_hold_char);
738 |
739 | /* yy_bp points to the position in yy_ch_buf of the start of
740 | * the current run.
741 | */
742 | yy_bp = yy_cp;
743 |
744 | yy_current_state = (yy_start);
745 | yy_match:
746 | do
747 | {
748 | register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
749 | if ( yy_accept[yy_current_state] )
750 | {
751 | (yy_last_accepting_state) = yy_current_state;
752 | (yy_last_accepting_cpos) = yy_cp;
753 | }
754 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
755 | {
756 | yy_current_state = (int) yy_def[yy_current_state];
757 | if ( yy_current_state >= 80 )
758 | yy_c = yy_meta[(unsigned int) yy_c];
759 | }
760 | yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
761 | ++yy_cp;
762 | }
763 | while ( yy_base[yy_current_state] != 145 );
764 |
765 | yy_find_action:
766 | yy_act = yy_accept[yy_current_state];
767 | if ( yy_act == 0 )
768 | { /* have to back up */
769 | yy_cp = (yy_last_accepting_cpos);
770 | yy_current_state = (yy_last_accepting_state);
771 | yy_act = yy_accept[yy_current_state];
772 | }
773 |
774 | YY_DO_BEFORE_ACTION;
775 |
776 | do_action: /* This label is used only to access EOF actions. */
777 |
778 | switch ( yy_act )
779 | { /* beginning of action switch */
780 | case 0: /* must back up */
781 | /* undo the effects of YY_DO_BEFORE_ACTION */
782 | *yy_cp = (yy_hold_char);
783 | yy_cp = (yy_last_accepting_cpos);
784 | yy_current_state = (yy_last_accepting_state);
785 | goto yy_find_action;
786 |
787 | case 1:
788 | #line 15 "semantics.l"
789 | case 2:
790 | #line 16 "semantics.l"
791 | case 3:
792 | #line 17 "semantics.l"
793 | case 4:
794 | #line 18 "semantics.l"
795 | case 5:
796 | #line 19 "semantics.l"
797 | case 6:
798 | #line 20 "semantics.l"
799 | case 7:
800 | #line 21 "semantics.l"
801 | case 8:
802 | #line 22 "semantics.l"
803 | case 9:
804 | #line 23 "semantics.l"
805 | case 10:
806 | YY_RULE_SETUP
807 | #line 23 "semantics.l"
808 | {yylval.dataType = strdup(yytext);return DATA_TYPE;}
809 | YY_BREAK
810 | case 11:
811 | YY_RULE_SETUP
812 | #line 25 "semantics.l"
813 | {yylval.dataType = strdup(yytext);return STRUCT;}
814 | YY_BREAK
815 | case 12:
816 | YY_RULE_SETUP
817 | #line 28 "semantics.l"
818 | {return SINGLE_QUOTES;}
819 | YY_BREAK
820 | case 13:
821 | YY_RULE_SETUP
822 | #line 29 "semantics.l"
823 | {return COMMA;}
824 | YY_BREAK
825 | case 14:
826 | YY_RULE_SETUP
827 | #line 30 "semantics.l"
828 | {return SEMI_COLON;}
829 | YY_BREAK
830 | case 15:
831 | YY_RULE_SETUP
832 | #line 31 "semantics.l"
833 | {return EQUALS;}
834 | YY_BREAK
835 | case 16:
836 | YY_RULE_SETUP
837 | #line 32 "semantics.l"
838 | {return BRACKET_OPEN;}
839 | YY_BREAK
840 | case 17:
841 | YY_RULE_SETUP
842 | #line 33 "semantics.l"
843 | {return BRACKET_CLOSE;}
844 | YY_BREAK
845 | case 18:
846 | YY_RULE_SETUP
847 | #line 34 "semantics.l"
848 | {return CURLY_BRACE_OPEN;}
849 | YY_BREAK
850 | case 19:
851 | YY_RULE_SETUP
852 | #line 35 "semantics.l"
853 | {return CURLY_BRACE_CLOSE;}
854 | YY_BREAK
855 | case 20:
856 | YY_RULE_SETUP
857 | #line 36 "semantics.l"
858 | {return BIG_BRACKET_OPEN;}
859 | YY_BREAK
860 | case 21:
861 | YY_RULE_SETUP
862 | #line 37 "semantics.l"
863 | {return BIG_BRACKET_CLOSE;}
864 | YY_BREAK
865 | case 22:
866 | YY_RULE_SETUP
867 | #line 39 "semantics.l"
868 | {yylval.charVal = yytext[1]; return CHARACTER_VALUE;}
869 | YY_BREAK
870 | case 23:
871 | YY_RULE_SETUP
872 | #line 40 "semantics.l"
873 | {yylval.intVal = atoi(yytext); return INTEGER_VALUE;}
874 | YY_BREAK
875 | case 24:
876 | YY_RULE_SETUP
877 | #line 41 "semantics.l"
878 | {yylval.floatVal = atof(yytext); return FLOAT_VALUE;}
879 | YY_BREAK
880 | case 25:
881 | YY_RULE_SETUP
882 | #line 43 "semantics.l"
883 | {yylval.strVal = strdup(yytext); return ARRAY_IDENTIFIER;}
884 | YY_BREAK
885 | case 26:
886 | YY_RULE_SETUP
887 | #line 44 "semantics.l"
888 | {yylval.dataType = strdup(yytext); return IDENTIFIER;}
889 | YY_BREAK
890 | case 27:
891 | /* rule 27 can match eol */
892 | YY_RULE_SETUP
893 | #line 47 "semantics.l"
894 | {yylval.strVal = strdup(yytext); return STRING_VALUE;}
895 | YY_BREAK
896 | case 28:
897 | /* rule 28 can match eol */
898 | YY_RULE_SETUP
899 | #line 50 "semantics.l"
900 | {yylineno++;}
901 | YY_BREAK
902 | case 29:
903 | YY_RULE_SETUP
904 | #line 51 "semantics.l"
905 | ;
906 | YY_BREAK
907 | case 30:
908 | YY_RULE_SETUP
909 | #line 52 "semantics.l"
910 | {InvalidToken();}
911 | YY_BREAK
912 | case 31:
913 | YY_RULE_SETUP
914 | #line 55 "semantics.l"
915 | ECHO;
916 | YY_BREAK
917 | #line 918 "lex.yy.c"
918 | case YY_STATE_EOF(INITIAL):
919 | yyterminate();
920 |
921 | case YY_END_OF_BUFFER:
922 | {
923 | /* Amount of text matched not including the EOB char. */
924 | int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
925 |
926 | /* Undo the effects of YY_DO_BEFORE_ACTION. */
927 | *yy_cp = (yy_hold_char);
928 | YY_RESTORE_YY_MORE_OFFSET
929 |
930 | if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
931 | {
932 | /* We're scanning a new file or input source. It's
933 | * possible that this happened because the user
934 | * just pointed yyin at a new source and called
935 | * yylex(). If so, then we have to assure
936 | * consistency between YY_CURRENT_BUFFER and our
937 | * globals. Here is the right place to do so, because
938 | * this is the first action (other than possibly a
939 | * back-up) that will match for the new input source.
940 | */
941 | (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
942 | YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
943 | YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
944 | }
945 |
946 | /* Note that here we test for yy_c_buf_p "<=" to the position
947 | * of the first EOB in the buffer, since yy_c_buf_p will
948 | * already have been incremented past the NUL character
949 | * (since all states make transitions on EOB to the
950 | * end-of-buffer state). Contrast this with the test
951 | * in input().
952 | */
953 | if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
954 | { /* This was really a NUL. */
955 | yy_state_type yy_next_state;
956 |
957 | (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
958 |
959 | yy_current_state = yy_get_previous_state( );
960 |
961 | /* Okay, we're now positioned to make the NUL
962 | * transition. We couldn't have
963 | * yy_get_previous_state() go ahead and do it
964 | * for us because it doesn't know how to deal
965 | * with the possibility of jamming (and we don't
966 | * want to build jamming into it because then it
967 | * will run more slowly).
968 | */
969 |
970 | yy_next_state = yy_try_NUL_trans( yy_current_state );
971 |
972 | yy_bp = (yytext_ptr) + YY_MORE_ADJ;
973 |
974 | if ( yy_next_state )
975 | {
976 | /* Consume the NUL. */
977 | yy_cp = ++(yy_c_buf_p);
978 | yy_current_state = yy_next_state;
979 | goto yy_match;
980 | }
981 |
982 | else
983 | {
984 | yy_cp = (yy_c_buf_p);
985 | goto yy_find_action;
986 | }
987 | }
988 |
989 | else switch ( yy_get_next_buffer( ) )
990 | {
991 | case EOB_ACT_END_OF_FILE:
992 | {
993 | (yy_did_buffer_switch_on_eof) = 0;
994 |
995 | if ( yywrap( ) )
996 | {
997 | /* Note: because we've taken care in
998 | * yy_get_next_buffer() to have set up
999 | * yytext, we can now set up
1000 | * yy_c_buf_p so that if some total
1001 | * hoser (like flex itself) wants to
1002 | * call the scanner after we return the
1003 | * YY_NULL, it'll still work - another
1004 | * YY_NULL will get returned.
1005 | */
1006 | (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
1007 |
1008 | yy_act = YY_STATE_EOF(YY_START);
1009 | goto do_action;
1010 | }
1011 |
1012 | else
1013 | {
1014 | if ( ! (yy_did_buffer_switch_on_eof) )
1015 | YY_NEW_FILE;
1016 | }
1017 | break;
1018 | }
1019 |
1020 | case EOB_ACT_CONTINUE_SCAN:
1021 | (yy_c_buf_p) =
1022 | (yytext_ptr) + yy_amount_of_matched_text;
1023 |
1024 | yy_current_state = yy_get_previous_state( );
1025 |
1026 | yy_cp = (yy_c_buf_p);
1027 | yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1028 | goto yy_match;
1029 |
1030 | case EOB_ACT_LAST_MATCH:
1031 | (yy_c_buf_p) =
1032 | &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
1033 |
1034 | yy_current_state = yy_get_previous_state( );
1035 |
1036 | yy_cp = (yy_c_buf_p);
1037 | yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1038 | goto yy_find_action;
1039 | }
1040 | break;
1041 | }
1042 |
1043 | default:
1044 | YY_FATAL_ERROR(
1045 | "fatal flex scanner internal error--no action found" );
1046 | } /* end of action switch */
1047 | } /* end of scanning one token */
1048 | } /* end of yylex */
1049 |
1050 | /* yy_get_next_buffer - try to read in a new buffer
1051 | *
1052 | * Returns a code representing an action:
1053 | * EOB_ACT_LAST_MATCH -
1054 | * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1055 | * EOB_ACT_END_OF_FILE - end of file
1056 | */
1057 | static int yy_get_next_buffer (void)
1058 | {
1059 | register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1060 | register char *source = (yytext_ptr);
1061 | register int number_to_move, i;
1062 | int ret_val;
1063 |
1064 | if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
1065 | YY_FATAL_ERROR(
1066 | "fatal flex scanner internal error--end of buffer missed" );
1067 |
1068 | if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1069 | { /* Don't try to fill the buffer, so this is an EOF. */
1070 | if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
1071 | {
1072 | /* We matched a single character, the EOB, so
1073 | * treat this as a final EOF.
1074 | */
1075 | return EOB_ACT_END_OF_FILE;
1076 | }
1077 |
1078 | else
1079 | {
1080 | /* We matched some text prior to the EOB, first
1081 | * process it.
1082 | */
1083 | return EOB_ACT_LAST_MATCH;
1084 | }
1085 | }
1086 |
1087 | /* Try to read more data. */
1088 |
1089 | /* First move last chars to start of buffer. */
1090 | number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
1091 |
1092 | for ( i = 0; i < number_to_move; ++i )
1093 | *(dest++) = *(source++);
1094 |
1095 | if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1096 | /* don't do the read, it's not guaranteed to return an EOF,
1097 | * just force an EOF
1098 | */
1099 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
1100 |
1101 | else
1102 | {
1103 | yy_size_t num_to_read =
1104 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1105 |
1106 | while ( num_to_read <= 0 )
1107 | { /* Not enough room in the buffer - grow it. */
1108 |
1109 | /* just a shorter name for the current buffer */
1110 | YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
1111 |
1112 | int yy_c_buf_p_offset =
1113 | (int) ((yy_c_buf_p) - b->yy_ch_buf);
1114 |
1115 | if ( b->yy_is_our_buffer )
1116 | {
1117 | yy_size_t new_size = b->yy_buf_size * 2;
1118 |
1119 | if ( new_size <= 0 )
1120 | b->yy_buf_size += b->yy_buf_size / 8;
1121 | else
1122 | b->yy_buf_size *= 2;
1123 |
1124 | b->yy_ch_buf = (char *)
1125 | /* Include room in for 2 EOB chars. */
1126 | yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
1127 | }
1128 | else
1129 | /* Can't grow it, we don't own it. */
1130 | b->yy_ch_buf = 0;
1131 |
1132 | if ( ! b->yy_ch_buf )
1133 | YY_FATAL_ERROR(
1134 | "fatal error - scanner input buffer overflow" );
1135 |
1136 | (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
1137 |
1138 | num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1139 | number_to_move - 1;
1140 |
1141 | }
1142 |
1143 | if ( num_to_read > YY_READ_BUF_SIZE )
1144 | num_to_read = YY_READ_BUF_SIZE;
1145 |
1146 | /* Read in more data. */
1147 | YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1148 | (yy_n_chars), num_to_read );
1149 |
1150 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1151 | }
1152 |
1153 | if ( (yy_n_chars) == 0 )
1154 | {
1155 | if ( number_to_move == YY_MORE_ADJ )
1156 | {
1157 | ret_val = EOB_ACT_END_OF_FILE;
1158 | yyrestart(yyin );
1159 | }
1160 |
1161 | else
1162 | {
1163 | ret_val = EOB_ACT_LAST_MATCH;
1164 | YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1165 | YY_BUFFER_EOF_PENDING;
1166 | }
1167 | }
1168 |
1169 | else
1170 | ret_val = EOB_ACT_CONTINUE_SCAN;
1171 |
1172 | if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1173 | /* Extend the array by 50%, plus the number we really need. */
1174 | yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1175 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
1176 | if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1177 | YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1178 | }
1179 |
1180 | (yy_n_chars) += number_to_move;
1181 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
1182 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
1183 |
1184 | (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1185 |
1186 | return ret_val;
1187 | }
1188 |
1189 | /* yy_get_previous_state - get the state just before the EOB char was reached */
1190 |
1191 | static yy_state_type yy_get_previous_state (void)
1192 | {
1193 | register yy_state_type yy_current_state;
1194 | register char *yy_cp;
1195 |
1196 | yy_current_state = (yy_start);
1197 |
1198 | for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1199 | {
1200 | register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1201 | if ( yy_accept[yy_current_state] )
1202 | {
1203 | (yy_last_accepting_state) = yy_current_state;
1204 | (yy_last_accepting_cpos) = yy_cp;
1205 | }
1206 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1207 | {
1208 | yy_current_state = (int) yy_def[yy_current_state];
1209 | if ( yy_current_state >= 80 )
1210 | yy_c = yy_meta[(unsigned int) yy_c];
1211 | }
1212 | yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1213 | }
1214 |
1215 | return yy_current_state;
1216 | }
1217 |
1218 | /* yy_try_NUL_trans - try to make a transition on the NUL character
1219 | *
1220 | * synopsis
1221 | * next_state = yy_try_NUL_trans( current_state );
1222 | */
1223 | static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
1224 | {
1225 | register int yy_is_jam;
1226 | register char *yy_cp = (yy_c_buf_p);
1227 |
1228 | register YY_CHAR yy_c = 1;
1229 | if ( yy_accept[yy_current_state] )
1230 | {
1231 | (yy_last_accepting_state) = yy_current_state;
1232 | (yy_last_accepting_cpos) = yy_cp;
1233 | }
1234 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1235 | {
1236 | yy_current_state = (int) yy_def[yy_current_state];
1237 | if ( yy_current_state >= 80 )
1238 | yy_c = yy_meta[(unsigned int) yy_c];
1239 | }
1240 | yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1241 | yy_is_jam = (yy_current_state == 79);
1242 |
1243 | return yy_is_jam ? 0 : yy_current_state;
1244 | }
1245 |
1246 | static void yyunput (int c, register char * yy_bp )
1247 | {
1248 | register char *yy_cp;
1249 |
1250 | yy_cp = (yy_c_buf_p);
1251 |
1252 | /* undo effects of setting up yytext */
1253 | *yy_cp = (yy_hold_char);
1254 |
1255 | if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1256 | { /* need to shift things up to make room */
1257 | /* +2 for EOB chars. */
1258 | register yy_size_t number_to_move = (yy_n_chars) + 2;
1259 | register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
1260 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
1261 | register char *source =
1262 | &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
1263 |
1264 | while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1265 | *--dest = *--source;
1266 |
1267 | yy_cp += (int) (dest - source);
1268 | yy_bp += (int) (dest - source);
1269 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
1270 | (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
1271 |
1272 | if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1273 | YY_FATAL_ERROR( "flex scanner push-back overflow" );
1274 | }
1275 |
1276 | *--yy_cp = (char) c;
1277 |
1278 | (yytext_ptr) = yy_bp;
1279 | (yy_hold_char) = *yy_cp;
1280 | (yy_c_buf_p) = yy_cp;
1281 | }
1282 |
1283 | #ifndef YY_NO_INPUT
1284 | #ifdef __cplusplus
1285 | static int yyinput (void)
1286 | #else
1287 | static int input (void)
1288 | #endif
1289 |
1290 | {
1291 | int c;
1292 |
1293 | *(yy_c_buf_p) = (yy_hold_char);
1294 |
1295 | if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
1296 | {
1297 | /* yy_c_buf_p now points to the character we want to return.
1298 | * If this occurs *before* the EOB characters, then it's a
1299 | * valid NUL; if not, then we've hit the end of the buffer.
1300 | */
1301 | if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1302 | /* This was really a NUL. */
1303 | *(yy_c_buf_p) = '\0';
1304 |
1305 | else
1306 | { /* need more input */
1307 | yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
1308 | ++(yy_c_buf_p);
1309 |
1310 | switch ( yy_get_next_buffer( ) )
1311 | {
1312 | case EOB_ACT_LAST_MATCH:
1313 | /* This happens because yy_g_n_b()
1314 | * sees that we've accumulated a
1315 | * token and flags that we need to
1316 | * try matching the token before
1317 | * proceeding. But for input(),
1318 | * there's no matching to consider.
1319 | * So convert the EOB_ACT_LAST_MATCH
1320 | * to EOB_ACT_END_OF_FILE.
1321 | */
1322 |
1323 | /* Reset buffer status. */
1324 | yyrestart(yyin );
1325 |
1326 | /*FALLTHROUGH*/
1327 |
1328 | case EOB_ACT_END_OF_FILE:
1329 | {
1330 | if ( yywrap( ) )
1331 | return 0;
1332 |
1333 | if ( ! (yy_did_buffer_switch_on_eof) )
1334 | YY_NEW_FILE;
1335 | #ifdef __cplusplus
1336 | return yyinput();
1337 | #else
1338 | return input();
1339 | #endif
1340 | }
1341 |
1342 | case EOB_ACT_CONTINUE_SCAN:
1343 | (yy_c_buf_p) = (yytext_ptr) + offset;
1344 | break;
1345 | }
1346 | }
1347 | }
1348 |
1349 | c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
1350 | *(yy_c_buf_p) = '\0'; /* preserve yytext */
1351 | (yy_hold_char) = *++(yy_c_buf_p);
1352 |
1353 | return c;
1354 | }
1355 | #endif /* ifndef YY_NO_INPUT */
1356 |
1357 | /** Immediately switch to a different input stream.
1358 | * @param input_file A readable stream.
1359 | *
1360 | * @note This function does not reset the start condition to @c INITIAL .
1361 | */
1362 | void yyrestart (FILE * input_file )
1363 | {
1364 |
1365 | if ( ! YY_CURRENT_BUFFER ){
1366 | yyensure_buffer_stack ();
1367 | YY_CURRENT_BUFFER_LVALUE =
1368 | yy_create_buffer(yyin,YY_BUF_SIZE );
1369 | }
1370 |
1371 | yy_init_buffer(YY_CURRENT_BUFFER,input_file );
1372 | yy_load_buffer_state( );
1373 | }
1374 |
1375 | /** Switch to a different input buffer.
1376 | * @param new_buffer The new input buffer.
1377 | *
1378 | */
1379 | void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
1380 | {
1381 |
1382 | /* TODO. We should be able to replace this entire function body
1383 | * with
1384 | * yypop_buffer_state();
1385 | * yypush_buffer_state(new_buffer);
1386 | */
1387 | yyensure_buffer_stack ();
1388 | if ( YY_CURRENT_BUFFER == new_buffer )
1389 | return;
1390 |
1391 | if ( YY_CURRENT_BUFFER )
1392 | {
1393 | /* Flush out information for old buffer. */
1394 | *(yy_c_buf_p) = (yy_hold_char);
1395 | YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1396 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1397 | }
1398 |
1399 | YY_CURRENT_BUFFER_LVALUE = new_buffer;
1400 | yy_load_buffer_state( );
1401 |
1402 | /* We don't actually know whether we did this switch during
1403 | * EOF (yywrap()) processing, but the only time this flag
1404 | * is looked at is after yywrap() is called, so it's safe
1405 | * to go ahead and always set it.
1406 | */
1407 | (yy_did_buffer_switch_on_eof) = 1;
1408 | }
1409 |
1410 | static void yy_load_buffer_state (void)
1411 | {
1412 | (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1413 | (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1414 | yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1415 | (yy_hold_char) = *(yy_c_buf_p);
1416 | }
1417 |
1418 | /** Allocate and initialize an input buffer state.
1419 | * @param file A readable stream.
1420 | * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1421 | *
1422 | * @return the allocated buffer state.
1423 | */
1424 | YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
1425 | {
1426 | YY_BUFFER_STATE b;
1427 |
1428 | b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
1429 | if ( ! b )
1430 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1431 |
1432 | b->yy_buf_size = size;
1433 |
1434 | /* yy_ch_buf has to be 2 characters longer than the size given because
1435 | * we need to put in 2 end-of-buffer characters.
1436 | */
1437 | b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 );
1438 | if ( ! b->yy_ch_buf )
1439 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1440 |
1441 | b->yy_is_our_buffer = 1;
1442 |
1443 | yy_init_buffer(b,file );
1444 |
1445 | return b;
1446 | }
1447 |
1448 | /** Destroy the buffer.
1449 | * @param b a buffer created with yy_create_buffer()
1450 | *
1451 | */
1452 | void yy_delete_buffer (YY_BUFFER_STATE b )
1453 | {
1454 |
1455 | if ( ! b )
1456 | return;
1457 |
1458 | if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1459 | YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1460 |
1461 | if ( b->yy_is_our_buffer )
1462 | yyfree((void *) b->yy_ch_buf );
1463 |
1464 | yyfree((void *) b );
1465 | }
1466 |
1467 | #ifndef __cplusplus
1468 | extern int isatty (int );
1469 | #endif /* __cplusplus */
1470 |
1471 | /* Initializes or reinitializes a buffer.
1472 | * This function is sometimes called more than once on the same buffer,
1473 | * such as during a yyrestart() or at EOF.
1474 | */
1475 | static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
1476 |
1477 | {
1478 | int oerrno = errno;
1479 |
1480 | yy_flush_buffer(b );
1481 |
1482 | b->yy_input_file = file;
1483 | b->yy_fill_buffer = 1;
1484 |
1485 | /* If b is the current buffer, then yy_init_buffer was _probably_
1486 | * called from yyrestart() or through yy_get_next_buffer.
1487 | * In that case, we don't want to reset the lineno or column.
1488 | */
1489 | if (b != YY_CURRENT_BUFFER){
1490 | b->yy_bs_lineno = 1;
1491 | b->yy_bs_column = 0;
1492 | }
1493 |
1494 | b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
1495 |
1496 | errno = oerrno;
1497 | }
1498 |
1499 | /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1500 | * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1501 | *
1502 | */
1503 | void yy_flush_buffer (YY_BUFFER_STATE b )
1504 | {
1505 | if ( ! b )
1506 | return;
1507 |
1508 | b->yy_n_chars = 0;
1509 |
1510 | /* We always need two end-of-buffer characters. The first causes
1511 | * a transition to the end-of-buffer state. The second causes
1512 | * a jam in that state.
1513 | */
1514 | b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1515 | b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1516 |
1517 | b->yy_buf_pos = &b->yy_ch_buf[0];
1518 |
1519 | b->yy_at_bol = 1;
1520 | b->yy_buffer_status = YY_BUFFER_NEW;
1521 |
1522 | if ( b == YY_CURRENT_BUFFER )
1523 | yy_load_buffer_state( );
1524 | }
1525 |
1526 | /** Pushes the new state onto the stack. The new state becomes
1527 | * the current state. This function will allocate the stack
1528 | * if necessary.
1529 | * @param new_buffer The new state.
1530 | *
1531 | */
1532 | void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
1533 | {
1534 | if (new_buffer == NULL)
1535 | return;
1536 |
1537 | yyensure_buffer_stack();
1538 |
1539 | /* This block is copied from yy_switch_to_buffer. */
1540 | if ( YY_CURRENT_BUFFER )
1541 | {
1542 | /* Flush out information for old buffer. */
1543 | *(yy_c_buf_p) = (yy_hold_char);
1544 | YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1545 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1546 | }
1547 |
1548 | /* Only push if top exists. Otherwise, replace top. */
1549 | if (YY_CURRENT_BUFFER)
1550 | (yy_buffer_stack_top)++;
1551 | YY_CURRENT_BUFFER_LVALUE = new_buffer;
1552 |
1553 | /* copied from yy_switch_to_buffer. */
1554 | yy_load_buffer_state( );
1555 | (yy_did_buffer_switch_on_eof) = 1;
1556 | }
1557 |
1558 | /** Removes and deletes the top of the stack, if present.
1559 | * The next element becomes the new top.
1560 | *
1561 | */
1562 | void yypop_buffer_state (void)
1563 | {
1564 | if (!YY_CURRENT_BUFFER)
1565 | return;
1566 |
1567 | yy_delete_buffer(YY_CURRENT_BUFFER );
1568 | YY_CURRENT_BUFFER_LVALUE = NULL;
1569 | if ((yy_buffer_stack_top) > 0)
1570 | --(yy_buffer_stack_top);
1571 |
1572 | if (YY_CURRENT_BUFFER) {
1573 | yy_load_buffer_state( );
1574 | (yy_did_buffer_switch_on_eof) = 1;
1575 | }
1576 | }
1577 |
1578 | /* Allocates the stack if it does not exist.
1579 | * Guarantees space for at least one push.
1580 | */
1581 | static void yyensure_buffer_stack (void)
1582 | {
1583 | yy_size_t num_to_alloc;
1584 |
1585 | if (!(yy_buffer_stack)) {
1586 |
1587 | /* First allocation is just for 2 elements, since we don't know if this
1588 | * scanner will even need a stack. We use 2 instead of 1 to avoid an
1589 | * immediate realloc on the next call.
1590 | */
1591 | num_to_alloc = 1;
1592 | (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1593 | (num_to_alloc * sizeof(struct yy_buffer_state*)
1594 | );
1595 | if ( ! (yy_buffer_stack) )
1596 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1597 |
1598 | memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1599 |
1600 | (yy_buffer_stack_max) = num_to_alloc;
1601 | (yy_buffer_stack_top) = 0;
1602 | return;
1603 | }
1604 |
1605 | if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1606 |
1607 | /* Increase the buffer to prepare for a possible push. */
1608 | int grow_size = 8 /* arbitrary grow size */;
1609 |
1610 | num_to_alloc = (yy_buffer_stack_max) + grow_size;
1611 | (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
1612 | ((yy_buffer_stack),
1613 | num_to_alloc * sizeof(struct yy_buffer_state*)
1614 | );
1615 | if ( ! (yy_buffer_stack) )
1616 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1617 |
1618 | /* zero only the new slots.*/
1619 | memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
1620 | (yy_buffer_stack_max) = num_to_alloc;
1621 | }
1622 | }
1623 |
1624 | /** Setup the input buffer state to scan directly from a user-specified character buffer.
1625 | * @param base the character buffer
1626 | * @param size the size in bytes of the character buffer
1627 | *
1628 | * @return the newly allocated buffer state object.
1629 | */
1630 | YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
1631 | {
1632 | YY_BUFFER_STATE b;
1633 |
1634 | if ( size < 2 ||
1635 | base[size-2] != YY_END_OF_BUFFER_CHAR ||
1636 | base[size-1] != YY_END_OF_BUFFER_CHAR )
1637 | /* They forgot to leave room for the EOB's. */
1638 | return 0;
1639 |
1640 | b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
1641 | if ( ! b )
1642 | YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
1643 |
1644 | b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
1645 | b->yy_buf_pos = b->yy_ch_buf = base;
1646 | b->yy_is_our_buffer = 0;
1647 | b->yy_input_file = 0;
1648 | b->yy_n_chars = b->yy_buf_size;
1649 | b->yy_is_interactive = 0;
1650 | b->yy_at_bol = 1;
1651 | b->yy_fill_buffer = 0;
1652 | b->yy_buffer_status = YY_BUFFER_NEW;
1653 |
1654 | yy_switch_to_buffer(b );
1655 |
1656 | return b;
1657 | }
1658 |
1659 | /** Setup the input buffer state to scan a string. The next call to yylex() will
1660 | * scan from a @e copy of @a str.
1661 | * @param yystr a NUL-terminated string to scan
1662 | *
1663 | * @return the newly allocated buffer state object.
1664 | * @note If you want to scan bytes that may contain NUL values, then use
1665 | * yy_scan_bytes() instead.
1666 | */
1667 | YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
1668 | {
1669 |
1670 | return yy_scan_bytes(yystr,strlen(yystr) );
1671 | }
1672 |
1673 | /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1674 | * scan from a @e copy of @a bytes.
1675 | * @param bytes the byte buffer to scan
1676 | * @param len the number of bytes in the buffer pointed to by @a bytes.
1677 | *
1678 | * @return the newly allocated buffer state object.
1679 | */
1680 | YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
1681 | {
1682 | YY_BUFFER_STATE b;
1683 | char *buf;
1684 | yy_size_t n, i;
1685 |
1686 | /* Get memory for full buffer, including space for trailing EOB's. */
1687 | n = _yybytes_len + 2;
1688 | buf = (char *) yyalloc(n );
1689 | if ( ! buf )
1690 | YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1691 |
1692 | for ( i = 0; i < _yybytes_len; ++i )
1693 | buf[i] = yybytes[i];
1694 |
1695 | buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
1696 |
1697 | b = yy_scan_buffer(buf,n );
1698 | if ( ! b )
1699 | YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
1700 |
1701 | /* It's okay to grow etc. this buffer, and we should throw it
1702 | * away when we're done.
1703 | */
1704 | b->yy_is_our_buffer = 1;
1705 |
1706 | return b;
1707 | }
1708 |
1709 | #ifndef YY_EXIT_FAILURE
1710 | #define YY_EXIT_FAILURE 2
1711 | #endif
1712 |
1713 | static void yy_fatal_error (yyconst char* msg )
1714 | {
1715 | (void) fprintf( stderr, "%s\n", msg );
1716 | exit( YY_EXIT_FAILURE );
1717 | }
1718 |
1719 | /* Redefine yyless() so it works in section 3 code. */
1720 |
1721 | #undef yyless
1722 | #define yyless(n) \
1723 | do \
1724 | { \
1725 | /* Undo effects of setting up yytext. */ \
1726 | int yyless_macro_arg = (n); \
1727 | YY_LESS_LINENO(yyless_macro_arg);\
1728 | yytext[yyleng] = (yy_hold_char); \
1729 | (yy_c_buf_p) = yytext + yyless_macro_arg; \
1730 | (yy_hold_char) = *(yy_c_buf_p); \
1731 | *(yy_c_buf_p) = '\0'; \
1732 | yyleng = yyless_macro_arg; \
1733 | } \
1734 | while ( 0 )
1735 |
1736 | /* Accessor methods (get/set functions) to struct members. */
1737 |
1738 | /** Get the current line number.
1739 | *
1740 | */
1741 | int yyget_lineno (void)
1742 | {
1743 |
1744 | return yylineno;
1745 | }
1746 |
1747 | /** Get the input stream.
1748 | *
1749 | */
1750 | FILE *yyget_in (void)
1751 | {
1752 | return yyin;
1753 | }
1754 |
1755 | /** Get the output stream.
1756 | *
1757 | */
1758 | FILE *yyget_out (void)
1759 | {
1760 | return yyout;
1761 | }
1762 |
1763 | /** Get the length of the current token.
1764 | *
1765 | */
1766 | yy_size_t yyget_leng (void)
1767 | {
1768 | return yyleng;
1769 | }
1770 |
1771 | /** Get the current token.
1772 | *
1773 | */
1774 |
1775 | char *yyget_text (void)
1776 | {
1777 | return yytext;
1778 | }
1779 |
1780 | /** Set the current line number.
1781 | * @param line_number
1782 | *
1783 | */
1784 | void yyset_lineno (int line_number )
1785 | {
1786 |
1787 | yylineno = line_number;
1788 | }
1789 |
1790 | /** Set the input stream. This does not discard the current
1791 | * input buffer.
1792 | * @param in_str A readable stream.
1793 | *
1794 | * @see yy_switch_to_buffer
1795 | */
1796 | void yyset_in (FILE * in_str )
1797 | {
1798 | yyin = in_str ;
1799 | }
1800 |
1801 | void yyset_out (FILE * out_str )
1802 | {
1803 | yyout = out_str ;
1804 | }
1805 |
1806 | int yyget_debug (void)
1807 | {
1808 | return yy_flex_debug;
1809 | }
1810 |
1811 | void yyset_debug (int bdebug )
1812 | {
1813 | yy_flex_debug = bdebug ;
1814 | }
1815 |
1816 | static int yy_init_globals (void)
1817 | {
1818 | /* Initialization is the same as for the non-reentrant scanner.
1819 | * This function is called from yylex_destroy(), so don't allocate here.
1820 | */
1821 |
1822 | (yy_buffer_stack) = 0;
1823 | (yy_buffer_stack_top) = 0;
1824 | (yy_buffer_stack_max) = 0;
1825 | (yy_c_buf_p) = (char *) 0;
1826 | (yy_init) = 0;
1827 | (yy_start) = 0;
1828 |
1829 | /* Defined in main.c */
1830 | #ifdef YY_STDINIT
1831 | yyin = stdin;
1832 | yyout = stdout;
1833 | #else
1834 | yyin = (FILE *) 0;
1835 | yyout = (FILE *) 0;
1836 | #endif
1837 |
1838 | /* For future reference: Set errno on error, since we are called by
1839 | * yylex_init()
1840 | */
1841 | return 0;
1842 | }
1843 |
1844 | /* yylex_destroy is for both reentrant and non-reentrant scanners. */
1845 | int yylex_destroy (void)
1846 | {
1847 |
1848 | /* Pop the buffer stack, destroying each element. */
1849 | while(YY_CURRENT_BUFFER){
1850 | yy_delete_buffer(YY_CURRENT_BUFFER );
1851 | YY_CURRENT_BUFFER_LVALUE = NULL;
1852 | yypop_buffer_state();
1853 | }
1854 |
1855 | /* Destroy the stack itself. */
1856 | yyfree((yy_buffer_stack) );
1857 | (yy_buffer_stack) = NULL;
1858 |
1859 | /* Reset the globals. This is important in a non-reentrant scanner so the next time
1860 | * yylex() is called, initialization will occur. */
1861 | yy_init_globals( );
1862 |
1863 | return 0;
1864 | }
1865 |
1866 | /*
1867 | * Internal utility routines.
1868 | */
1869 |
1870 | #ifndef yytext_ptr
1871 | static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1872 | {
1873 | register int i;
1874 | for ( i = 0; i < n; ++i )
1875 | s1[i] = s2[i];
1876 | }
1877 | #endif
1878 |
1879 | #ifdef YY_NEED_STRLEN
1880 | static int yy_flex_strlen (yyconst char * s )
1881 | {
1882 | register int n;
1883 | for ( n = 0; s[n]; ++n )
1884 | ;
1885 |
1886 | return n;
1887 | }
1888 | #endif
1889 |
1890 | void *yyalloc (yy_size_t size )
1891 | {
1892 | return (void *) malloc( size );
1893 | }
1894 |
1895 | void *yyrealloc (void * ptr, yy_size_t size )
1896 | {
1897 | /* The cast to (char *) in the following accommodates both
1898 | * implementations that use char* generic pointers, and those
1899 | * that use void* generic pointers. It works with the latter
1900 | * because both ANSI C and C++ allow castless assignment from
1901 | * any pointer type to void*, and deal with argument conversions
1902 | * as though doing an assignment.
1903 | */
1904 | return (void *) realloc( (char *) ptr, size );
1905 | }
1906 |
1907 | void yyfree (void * ptr )
1908 | {
1909 | free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
1910 | }
1911 |
1912 | #define YYTABLES_NAME "yytables"
1913 |
1914 | #line 55 "semantics.l"
1915 |
1916 |
1917 |
1918 | int yywrap(void){
1919 | return 1;
1920 | }
1921 |
1922 | void yyerror(char *s) {
1923 | fprintf(stderr, "\nERROR ON LINE %d : \n %s\n", yylineno, s);
1924 | exit(0);
1925 | }
1926 |
1927 | void InvalidToken(){
1928 | printf("ERROR ON LINE %d : \n Invalid Token %s\n", yylineno,yytext);
1929 | exit(0);
1930 | }
1931 |
1932 |
--------------------------------------------------------------------------------
/output:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajhalthor/interpreter/28cbdb78e4bfe2f30a6877da69fe2bd86bbdb318/output
--------------------------------------------------------------------------------
/sample:
--------------------------------------------------------------------------------
1 | int f = 4;
2 | char p='c';
3 | struct ss{
4 | int gg;
5 | float ww;
6 | }aaaa,bb,cc,ff;
7 | int ddd = 77,d;
8 | char c[8];
9 | int feg[9];
10 | void man(int,int);
11 | int x;
12 | int manY;
13 |
--------------------------------------------------------------------------------
/semantics.l:
--------------------------------------------------------------------------------
1 | %{
2 | #include
3 | #include
4 | #include "y.tab.h"
5 | void extern yyerror(char*);
6 | void InvalidToken();
7 |
8 | %}
9 |
10 | whitespace [ \t\r\v\f]
11 | linefeed \n
12 |
13 | %%
14 | "void" |
15 | "int" |
16 | "char" |
17 | "float" |
18 | "unsigned int" |
19 | "unsigned char" |
20 | "void*" |
21 | "int*" |
22 | "char*" |
23 | "float*" {yylval.dataType = strdup(yytext);return DATA_TYPE;}
24 |
25 | "struct" {yylval.dataType = strdup(yytext);return STRUCT;}
26 |
27 |
28 | "'" {return SINGLE_QUOTES;}
29 | "," {return COMMA;}
30 | ";" {return SEMI_COLON;}
31 | "=" {return EQUALS;}
32 | "(" {return BRACKET_OPEN;}
33 | ")" {return BRACKET_CLOSE;}
34 | "{" {return CURLY_BRACE_OPEN;}
35 | "}" {return CURLY_BRACE_CLOSE;}
36 | "[" {return BIG_BRACKET_OPEN;}
37 | "]" {return BIG_BRACKET_CLOSE;}
38 |
39 | [\'][a-zA-Z][\'] {yylval.charVal = yytext[1]; return CHARACTER_VALUE;}
40 | [-+]?[0-9]+ {yylval.intVal = atoi(yytext); return INTEGER_VALUE;}
41 | [-+]?[0-9]*\.?[0-9]+ {yylval.floatVal = atof(yytext); return FLOAT_VALUE;}
42 |
43 | [a-zA-Z][_a-zA-Z0-9]*(\[[0-9]+\])+ {yylval.strVal = strdup(yytext); return ARRAY_IDENTIFIER;}
44 | [a-zA-Z][_a-zA-Z0-9]* {yylval.dataType = strdup(yytext); return IDENTIFIER;}
45 |
46 |
47 | \"(\\.|[^"])*\" {yylval.strVal = strdup(yytext); return STRING_VALUE;}
48 |
49 |
50 | {linefeed} {yylineno++;}
51 | {whitespace} ;
52 | . {InvalidToken();}
53 |
54 |
55 | %%
56 |
57 | int yywrap(void){
58 | return 1;
59 | }
60 |
61 | void yyerror(char *s) {
62 | fprintf(stderr, "\nERROR ON LINE %d : \n %s\n", yylineno, s);
63 | exit(0);
64 | }
65 |
66 | void InvalidToken(){
67 | printf("ERROR ON LINE %d : \n Invalid Token %s\n", yylineno,yytext);
68 | exit(0);
69 | }
70 |
--------------------------------------------------------------------------------
/syntax2.y:
--------------------------------------------------------------------------------
1 | %{
2 | #include
3 | #include
4 |
5 | #include "HeaderFiles/langFunctions.h"
6 | #include "HeaderFiles/validators.h"
7 |
8 | extern char Data_Type[50];
9 |
10 | extern void yyerror();
11 | extern int yylex();
12 | extern char* yytext;
13 | extern int yylineno;
14 |
15 | void storeDataType(char*);
16 | int isDuplicate(char*, char*);
17 | void storeIdentifier(char*,char*);
18 | void DuplicateIdentifierError(char*);
19 | char* retrieveDataType();
20 | void clearBuffers();
21 | int isValidAssignment(char*);
22 | void AssignmentError(char*);
23 | char* extractIdentifier(char[]);
24 |
25 | //For Array Identifiers
26 | int noOfArrayIdentifiers=0;
27 | char extractedIdentifier[50][50];
28 |
29 | %}
30 |
31 |
32 | %define parse.lac full
33 | %define parse.error verbose
34 |
35 |
36 | %union {
37 | int intVal;
38 | char* dataType;
39 | char* strVal;
40 | float floatVal;
41 | char charVal;
42 | }
43 |
44 |
45 |
46 | %token COMMA SINGLE_QUOTES SEMI_COLON EQUALS
47 | %token BRACKET_OPEN BRACKET_CLOSE CURLY_BRACE_OPEN CURLY_BRACE_CLOSE BIG_BRACKET_OPEN BIG_BRACKET_CLOSE
48 |
49 | %token CHARACTER_VALUE
50 | %token INTEGER_VALUE
51 | %token FLOAT_VALUE
52 | %token STRING_VALUE
53 |
54 |
55 | %token INT
56 | %token FLOAT
57 | %token STRING
58 | %token DATA_TYPE
59 | %token IDENTIFIER ARRAY_IDENTIFIER
60 | %token STRUCT
61 |
62 | %type DECLARATION
63 | %type EXPRESSION
64 | %type FUNCTION_DECLARATION
65 |
66 |
67 |
68 | %%
69 |
70 | DECLARATION : EXPRESSION SEMI_COLON { clearBuffers(); }
71 | | FUNCTION_DECLARATION SEMI_COLON
72 | | STRUCT IDENTIFIER STRUCTURE_DEFINITION SEMI_COLON
73 | | STRUCT IDENTIFIER STRUCTURE_DEFINITION IDENTIFIER_LIST SEMI_COLON
74 | | DECLARATION EXPRESSION SEMI_COLON { clearBuffers(); }
75 | | DECLARATION FUNCTION_DECLARATION SEMI_COLON
76 | | DECLARATION STRUCT IDENTIFIER STRUCTURE_DEFINITION SEMI_COLON
77 | | DECLARATION STRUCT IDENTIFIER STRUCTURE_DEFINITION IDENTIFIER_LIST SEMI_COLON
78 |
79 | | error '>' {/* ' > ' stops execution all together */}
80 | ;
81 |
82 | EXPRESSION : DATA_TYPE IDENTIFIER {
83 | if(!isDuplicate($2,retrieveDataType())){
84 | storeIdentifier($2,retrieveDataType());
85 | storeDataType($1);
86 | }else{
87 | DuplicateIdentifierError($2);
88 | }
89 | }
90 |
91 |
92 |
93 | | EXPRESSION EQUALS NUMBER {;}
94 |
95 | | EXPRESSION COMMA IDENTIFIER {
96 | if(!isDuplicate($3,retrieveDataType())){
97 | storeIdentifier($3,retrieveDataType());
98 | }else{
99 | DuplicateIdentifierError($3);
100 | }
101 | }
102 |
103 |
104 |
105 |
106 | | DATA_TYPE ARRAY_IDENTIFIER {
107 |
108 | strcpy(extractedIdentifier[noOfArrayIdentifiers],extractIdentifier($2));
109 | if(!isDuplicate(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType())){
110 | storeIdentifier(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType());
111 | storeDataType($1);
112 | }else{
113 | DuplicateIdentifierError(extractedIdentifier[noOfArrayIdentifiers]);
114 | }
115 | noOfArrayIdentifiers++;
116 | }
117 |
118 | | EXPRESSION EQUALS CURLY_BRACE_OPEN PARAMETER_LIST CURLY_BRACE_CLOSE
119 |
120 | | EXPRESSION COMMA ARRAY_IDENTIFIER {
121 | strcpy(extractedIdentifier[noOfArrayIdentifiers],extractIdentifier($3));
122 | if(!isDuplicate(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType())){
123 | storeIdentifier(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType());
124 | }else{
125 | DuplicateIdentifierError(extractedIdentifier[noOfArrayIdentifiers]);
126 | }
127 | noOfArrayIdentifiers++;
128 | }
129 |
130 |
131 | | error '>' {/* no need to call yyerror cuz of line 1570 of y.tab.c*/}
132 | ;
133 |
134 |
135 | NUMBER : INTEGER_VALUE {if(!isValidAssignment("int")){ AssignmentError(itoa($1));}}
136 | | FLOAT_VALUE {if(!isValidAssignment("float")){ AssignmentError(ftoa($1));}}
137 | | CHARACTER_VALUE {if(!isValidAssignment("char")){ AssignmentError(ctoa($1));} }
138 | | STRING_VALUE {if(!isValidAssignment("char*")){ AssignmentError($1);} }
139 | ;
140 |
141 |
142 | PARAMETER_LIST : NUMBER
143 | | PARAMETER_LIST COMMA NUMBER
144 | | NUMBER EQUALS NUMBER { yyerror("Two or more equal signs are not allowed in C");}
145 | | error '>'
146 | ;
147 |
148 |
149 | STRUCTURE_DEFINITION : CURLY_BRACE_OPEN DECLARATION CURLY_BRACE_CLOSE
150 | ;
151 |
152 | FUNCTION_DECLARATION : DATA_TYPE IDENTIFIER BRACKET_OPEN DATA_TYPE_LIST BRACKET_CLOSE {
153 |
154 | if(!isDuplicate($2,retrieveDataType())){
155 | storeIdentifier($2,retrieveDataType());
156 | storeDataType($1);
157 | }else{
158 | DuplicateIdentifierError($2);
159 | }
160 |
161 | }
162 | ;
163 |
164 | IDENTIFIER_LIST : IDENTIFIER
165 | | IDENTIFIER_LIST COMMA IDENTIFIER
166 | ;
167 |
168 | DATA_TYPE_LIST : DATA_TYPE
169 | | DATA_TYPE_LIST COMMA DATA_TYPE
170 | ;
171 |
172 | %%
173 |
174 |
175 | int main(){
176 |
177 | yyparse();
178 | printf("No Errors!!\n");
179 | return 0;
180 | }
--------------------------------------------------------------------------------
/y.tab.c:
--------------------------------------------------------------------------------
1 | /* A Bison parser, made by GNU Bison 3.0.4. */
2 |
3 | /* Bison implementation for Yacc-like parsers in C
4 |
5 | Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see . */
19 |
20 | /* As a special exception, you may create a larger work that contains
21 | part or all of the Bison parser skeleton and distribute that work
22 | under terms of your choice, so long as that work isn't itself a
23 | parser generator using the skeleton or a modified version thereof
24 | as a parser skeleton. Alternatively, if you modify or redistribute
25 | the parser skeleton itself, you may (at your option) remove this
26 | special exception, which will cause the skeleton and the resulting
27 | Bison output files to be licensed under the GNU General Public
28 | License without this special exception.
29 |
30 | This special exception was added by the Free Software Foundation in
31 | version 2.2 of Bison. */
32 |
33 | /* C LALR(1) parser skeleton written by Richard Stallman, by
34 | simplifying the original so-called "semantic" parser. */
35 |
36 | /* All symbols defined below should begin with yy or YY, to avoid
37 | infringing on user name space. This should be done even for local
38 | variables, as they might otherwise be expanded by user macros.
39 | There are some unavoidable exceptions within include files to
40 | define necessary library symbols; they are noted "INFRINGES ON
41 | USER NAME SPACE" below. */
42 |
43 | /* Identify Bison output. */
44 | #define YYBISON 1
45 |
46 | /* Bison version. */
47 | #define YYBISON_VERSION "3.0.4"
48 |
49 | /* Skeleton name. */
50 | #define YYSKELETON_NAME "yacc.c"
51 |
52 | /* Pure parsers. */
53 | #define YYPURE 0
54 |
55 | /* Push parsers. */
56 | #define YYPUSH 0
57 |
58 | /* Pull parsers. */
59 | #define YYPULL 1
60 |
61 |
62 |
63 |
64 | /* Copy the first part of user declarations. */
65 | #line 1 "syntax2.y" /* yacc.c:339 */
66 |
67 | #include
68 | #include
69 |
70 | #include "HeaderFiles/langFunctions.h"
71 | #include "HeaderFiles/validators.h"
72 |
73 | extern char Data_Type[50];
74 |
75 | extern void yyerror();
76 | extern int yylex();
77 | extern char* yytext;
78 | extern int yylineno;
79 |
80 | void storeDataType(char*);
81 | int isDuplicate(char*, char*);
82 | void storeIdentifier(char*,char*);
83 | void DuplicateIdentifierError(char*);
84 | char* retrieveDataType();
85 | void clearBuffers();
86 | int isValidAssignment(char*);
87 | void AssignmentError(char*);
88 | char* extractIdentifier(char[]);
89 |
90 | //For Array Identifiers
91 | int noOfArrayIdentifiers=0;
92 | char extractedIdentifier[50][50];
93 |
94 |
95 | #line 96 "y.tab.c" /* yacc.c:339 */
96 |
97 | # ifndef YY_NULLPTR
98 | # if defined __cplusplus && 201103L <= __cplusplus
99 | # define YY_NULLPTR nullptr
100 | # else
101 | # define YY_NULLPTR 0
102 | # endif
103 | # endif
104 |
105 | /* Enabling verbose error messages. */
106 | #ifdef YYERROR_VERBOSE
107 | # undef YYERROR_VERBOSE
108 | # define YYERROR_VERBOSE 1
109 | #else
110 | # define YYERROR_VERBOSE 1
111 | #endif
112 |
113 | /* In a future release of Bison, this section will be replaced
114 | by #include "y.tab.h". */
115 | #ifndef YY_YY_Y_TAB_H_INCLUDED
116 | # define YY_YY_Y_TAB_H_INCLUDED
117 | /* Debug traces. */
118 | #ifndef YYDEBUG
119 | # define YYDEBUG 0
120 | #endif
121 | #if YYDEBUG
122 | extern int yydebug;
123 | #endif
124 |
125 | /* Token type. */
126 | #ifndef YYTOKENTYPE
127 | # define YYTOKENTYPE
128 | enum yytokentype
129 | {
130 | COMMA = 258,
131 | SINGLE_QUOTES = 259,
132 | SEMI_COLON = 260,
133 | EQUALS = 261,
134 | BRACKET_OPEN = 262,
135 | BRACKET_CLOSE = 263,
136 | CURLY_BRACE_OPEN = 264,
137 | CURLY_BRACE_CLOSE = 265,
138 | BIG_BRACKET_OPEN = 266,
139 | BIG_BRACKET_CLOSE = 267,
140 | CHARACTER_VALUE = 268,
141 | INTEGER_VALUE = 269,
142 | FLOAT_VALUE = 270,
143 | STRING_VALUE = 271,
144 | INT = 272,
145 | FLOAT = 273,
146 | STRING = 274,
147 | DATA_TYPE = 275,
148 | IDENTIFIER = 276,
149 | ARRAY_IDENTIFIER = 277,
150 | STRUCT = 278
151 | };
152 | #endif
153 | /* Tokens. */
154 | #define COMMA 258
155 | #define SINGLE_QUOTES 259
156 | #define SEMI_COLON 260
157 | #define EQUALS 261
158 | #define BRACKET_OPEN 262
159 | #define BRACKET_CLOSE 263
160 | #define CURLY_BRACE_OPEN 264
161 | #define CURLY_BRACE_CLOSE 265
162 | #define BIG_BRACKET_OPEN 266
163 | #define BIG_BRACKET_CLOSE 267
164 | #define CHARACTER_VALUE 268
165 | #define INTEGER_VALUE 269
166 | #define FLOAT_VALUE 270
167 | #define STRING_VALUE 271
168 | #define INT 272
169 | #define FLOAT 273
170 | #define STRING 274
171 | #define DATA_TYPE 275
172 | #define IDENTIFIER 276
173 | #define ARRAY_IDENTIFIER 277
174 | #define STRUCT 278
175 |
176 | /* Value type. */
177 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
178 |
179 | union YYSTYPE
180 | {
181 | #line 36 "syntax2.y" /* yacc.c:355 */
182 |
183 | int intVal;
184 | char* dataType;
185 | char* strVal;
186 | float floatVal;
187 | char charVal;
188 |
189 | #line 190 "y.tab.c" /* yacc.c:355 */
190 | };
191 |
192 | typedef union YYSTYPE YYSTYPE;
193 | # define YYSTYPE_IS_TRIVIAL 1
194 | # define YYSTYPE_IS_DECLARED 1
195 | #endif
196 |
197 |
198 | extern YYSTYPE yylval;
199 |
200 | int yyparse (void);
201 |
202 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */
203 |
204 | /* Copy the second part of user declarations. */
205 |
206 | #line 207 "y.tab.c" /* yacc.c:358 */
207 |
208 | #ifdef short
209 | # undef short
210 | #endif
211 |
212 | #ifdef YYTYPE_UINT8
213 | typedef YYTYPE_UINT8 yytype_uint8;
214 | #else
215 | typedef unsigned char yytype_uint8;
216 | #endif
217 |
218 | #ifdef YYTYPE_INT8
219 | typedef YYTYPE_INT8 yytype_int8;
220 | #else
221 | typedef signed char yytype_int8;
222 | #endif
223 |
224 | #ifdef YYTYPE_UINT16
225 | typedef YYTYPE_UINT16 yytype_uint16;
226 | #else
227 | typedef unsigned short int yytype_uint16;
228 | #endif
229 |
230 | #ifdef YYTYPE_INT16
231 | typedef YYTYPE_INT16 yytype_int16;
232 | #else
233 | typedef short int yytype_int16;
234 | #endif
235 |
236 | #ifndef YYSIZE_T
237 | # ifdef __SIZE_TYPE__
238 | # define YYSIZE_T __SIZE_TYPE__
239 | # elif defined size_t
240 | # define YYSIZE_T size_t
241 | # elif ! defined YYSIZE_T
242 | # include /* INFRINGES ON USER NAME SPACE */
243 | # define YYSIZE_T size_t
244 | # else
245 | # define YYSIZE_T unsigned int
246 | # endif
247 | #endif
248 |
249 | #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
250 |
251 | #ifndef YY_
252 | # if defined YYENABLE_NLS && YYENABLE_NLS
253 | # if ENABLE_NLS
254 | # include /* INFRINGES ON USER NAME SPACE */
255 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
256 | # endif
257 | # endif
258 | # ifndef YY_
259 | # define YY_(Msgid) Msgid
260 | # endif
261 | #endif
262 |
263 | #ifndef YY_ATTRIBUTE
264 | # if (defined __GNUC__ \
265 | && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
266 | || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
267 | # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
268 | # else
269 | # define YY_ATTRIBUTE(Spec) /* empty */
270 | # endif
271 | #endif
272 |
273 | #ifndef YY_ATTRIBUTE_PURE
274 | # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
275 | #endif
276 |
277 | #ifndef YY_ATTRIBUTE_UNUSED
278 | # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
279 | #endif
280 |
281 | #if !defined _Noreturn \
282 | && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
283 | # if defined _MSC_VER && 1200 <= _MSC_VER
284 | # define _Noreturn __declspec (noreturn)
285 | # else
286 | # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
287 | # endif
288 | #endif
289 |
290 | /* Suppress unused-variable warnings by "using" E. */
291 | #if ! defined lint || defined __GNUC__
292 | # define YYUSE(E) ((void) (E))
293 | #else
294 | # define YYUSE(E) /* empty */
295 | #endif
296 |
297 | #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
298 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */
299 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
300 | _Pragma ("GCC diagnostic push") \
301 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
302 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
303 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
304 | _Pragma ("GCC diagnostic pop")
305 | #else
306 | # define YY_INITIAL_VALUE(Value) Value
307 | #endif
308 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
309 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
310 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END
311 | #endif
312 | #ifndef YY_INITIAL_VALUE
313 | # define YY_INITIAL_VALUE(Value) /* Nothing. */
314 | #endif
315 |
316 |
317 | #if 1
318 |
319 | /* The parser invokes alloca or malloc; define the necessary symbols. */
320 |
321 | # ifdef YYSTACK_ALLOC
322 | /* Pacify GCC's 'empty if-body' warning. */
323 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
324 | # ifndef YYSTACK_ALLOC_MAXIMUM
325 | /* The OS might guarantee only one guard page at the bottom of the stack,
326 | and a page size can be as small as 4096 bytes. So we cannot safely
327 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
328 | to allow for a few compiler-allocated temporary stack slots. */
329 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
330 | # endif
331 | # else
332 | # define YYSTACK_ALLOC YYMALLOC
333 | # define YYSTACK_FREE YYFREE
334 | # ifndef YYSTACK_ALLOC_MAXIMUM
335 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
336 | # endif
337 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \
338 | && ! ((defined YYMALLOC || defined malloc) \
339 | && (defined YYFREE || defined free)))
340 | # include /* INFRINGES ON USER NAME SPACE */
341 | # ifndef EXIT_SUCCESS
342 | # define EXIT_SUCCESS 0
343 | # endif
344 | # endif
345 | # ifndef YYMALLOC
346 | # define YYMALLOC malloc
347 | # if ! defined malloc && ! defined EXIT_SUCCESS
348 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
349 | # endif
350 | # endif
351 | # ifndef YYFREE
352 | # define YYFREE free
353 | # if ! defined free && ! defined EXIT_SUCCESS
354 | void free (void *); /* INFRINGES ON USER NAME SPACE */
355 | # endif
356 | # endif
357 | # endif
358 | # define YYCOPY_NEEDED 1
359 | #endif
360 |
361 |
362 | #if (! defined yyoverflow \
363 | && (! defined __cplusplus \
364 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
365 |
366 | /* A type that is properly aligned for any stack member. */
367 | union yyalloc
368 | {
369 | yytype_int16 yyss_alloc;
370 | YYSTYPE yyvs_alloc;
371 | };
372 |
373 | /* The size of the maximum gap between one aligned stack and the next. */
374 | # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
375 |
376 | /* The size of an array large to enough to hold all stacks, each with
377 | N elements. */
378 | # define YYSTACK_BYTES(N) \
379 | ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
380 | + YYSTACK_GAP_MAXIMUM)
381 |
382 | # define YYCOPY_NEEDED 1
383 |
384 | /* Relocate STACK from its old location to the new one. The
385 | local variables YYSIZE and YYSTACKSIZE give the old and new number of
386 | elements in the stack, and YYPTR gives the new location of the
387 | stack. Advance YYPTR to a properly aligned location for the next
388 | stack. */
389 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
390 | do \
391 | { \
392 | YYSIZE_T yynewbytes; \
393 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
394 | Stack = &yyptr->Stack_alloc; \
395 | yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
396 | yyptr += yynewbytes / sizeof (*yyptr); \
397 | } \
398 | while (0)
399 |
400 | #endif
401 |
402 | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
403 | /* Copy COUNT objects from SRC to DST. The source and destination do
404 | not overlap. */
405 | # ifndef YYCOPY
406 | # if defined __GNUC__ && 1 < __GNUC__
407 | # define YYCOPY(Dst, Src, Count) \
408 | __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
409 | # else
410 | # define YYCOPY(Dst, Src, Count) \
411 | do \
412 | { \
413 | YYSIZE_T yyi; \
414 | for (yyi = 0; yyi < (Count); yyi++) \
415 | (Dst)[yyi] = (Src)[yyi]; \
416 | } \
417 | while (0)
418 | # endif
419 | # endif
420 | #endif /* !YYCOPY_NEEDED */
421 |
422 | /* YYFINAL -- State number of the termination state. */
423 | #define YYFINAL 11
424 | /* YYLAST -- Last index in YYTABLE. */
425 | #define YYLAST 72
426 |
427 | /* YYNTOKENS -- Number of terminals. */
428 | #define YYNTOKENS 25
429 | /* YYNNTS -- Number of nonterminals. */
430 | #define YYNNTS 9
431 | /* YYNRULES -- Number of rules. */
432 | #define YYNRULES 31
433 | /* YYNSTATES -- Number of states. */
434 | #define YYNSTATES 61
435 |
436 | /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
437 | by yylex, with out-of-bounds checking. */
438 | #define YYUNDEFTOK 2
439 | #define YYMAXUTOK 278
440 |
441 | #define YYTRANSLATE(YYX) \
442 | ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
443 |
444 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
445 | as returned by yylex, without out-of-bounds checking. */
446 | static const yytype_uint8 yytranslate[] =
447 | {
448 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
449 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
450 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
451 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
452 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
453 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
454 | 2, 2, 24, 2, 2, 2, 2, 2, 2, 2,
455 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
456 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
457 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
458 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
459 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
460 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
461 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
462 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
463 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
464 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
465 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
466 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
467 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
468 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
469 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
470 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
471 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
472 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
473 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
474 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
475 | 15, 16, 17, 18, 19, 20, 21, 22, 23
476 | };
477 |
478 | #if YYDEBUG
479 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
480 | static const yytype_uint8 yyrline[] =
481 | {
482 | 0, 70, 70, 71, 72, 73, 74, 75, 76, 77,
483 | 79, 82, 93, 95, 106, 118, 120, 131, 135, 136,
484 | 137, 138, 142, 143, 144, 145, 149, 152, 164, 165,
485 | 168, 169
486 | };
487 | #endif
488 |
489 | #if YYDEBUG || YYERROR_VERBOSE || 1
490 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
491 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */
492 | static const char *const yytname[] =
493 | {
494 | "$end", "error", "$undefined", "COMMA", "SINGLE_QUOTES", "SEMI_COLON",
495 | "EQUALS", "BRACKET_OPEN", "BRACKET_CLOSE", "CURLY_BRACE_OPEN",
496 | "CURLY_BRACE_CLOSE", "BIG_BRACKET_OPEN", "BIG_BRACKET_CLOSE",
497 | "CHARACTER_VALUE", "INTEGER_VALUE", "FLOAT_VALUE", "STRING_VALUE", "INT",
498 | "FLOAT", "STRING", "DATA_TYPE", "IDENTIFIER", "ARRAY_IDENTIFIER",
499 | "STRUCT", "'>'", "$accept", "DECLARATION", "EXPRESSION", "NUMBER",
500 | "PARAMETER_LIST", "STRUCTURE_DEFINITION", "FUNCTION_DECLARATION",
501 | "IDENTIFIER_LIST", "DATA_TYPE_LIST", YY_NULLPTR
502 | };
503 | #endif
504 |
505 | # ifdef YYPRINT
506 | /* YYTOKNUM[NUM] -- (External) token number corresponding to the
507 | (internal) symbol number NUM (which must be that of a token). */
508 | static const yytype_uint16 yytoknum[] =
509 | {
510 | 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
511 | 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
512 | 275, 276, 277, 278, 62
513 | };
514 | # endif
515 |
516 | #define YYPACT_NINF -28
517 |
518 | #define yypact_value_is_default(Yystate) \
519 | (!!((Yystate) == (-28)))
520 |
521 | #define YYTABLE_NINF -18
522 |
523 | #define yytable_value_is_error(Yytable_value) \
524 | 0
525 |
526 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
527 | STATE-NUM. */
528 | static const yytype_int8 yypact[] =
529 | {
530 | 15, -15, 26, -9, 5, 34, 12, 55, 7, -28,
531 | 22, -28, 17, 28, 59, 16, 45, -28, 37, -28,
532 | 39, 15, -1, -28, 22, -28, -28, -28, -28, 29,
533 | -28, -28, -28, -28, -28, -28, 0, 9, -28, -28,
534 | 10, 2, 44, 30, 8, 43, -28, -28, 48, -28,
535 | -28, 19, -28, 41, 41, -28, -28, -28, -28, -28,
536 | -28
537 | };
538 |
539 | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
540 | Performed when YYTABLE does not specify something else to do. Zero
541 | means the default is an error. */
542 | static const yytype_uint8 yydefact[] =
543 | {
544 | 0, 0, 0, 0, 0, 0, 0, 10, 11, 14,
545 | 0, 1, 0, 0, 0, 0, 0, 2, 0, 3,
546 | 0, 0, 0, 17, 0, 6, 7, 13, 16, 0,
547 | 20, 18, 19, 21, 12, 30, 0, 0, 4, 28,
548 | 0, 0, 0, 22, 0, 0, 27, 26, 0, 5,
549 | 8, 0, 25, 0, 0, 15, 31, 29, 9, 24,
550 | 23
551 | };
552 |
553 | /* YYPGOTO[NTERM-NUM]. */
554 | static const yytype_int8 yypgoto[] =
555 | {
556 | -28, 49, -4, -27, -28, 47, -3, 31, -28
557 | };
558 |
559 | /* YYDEFGOTO[NTERM-NUM]. */
560 | static const yytype_int8 yydefgoto[] =
561 | {
562 | -1, 4, 5, 34, 44, 22, 6, 40, 36
563 | };
564 |
565 | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
566 | positive, shift that token. If negative, reduce the rule whose
567 | number is the opposite. If YYTABLE_NINF, syntax error. */
568 | static const yytype_int8 yytable[] =
569 | {
570 | 14, 15, 43, 45, 38, 11, 12, 50, 46, 7,
571 | 12, 54, 10, 48, 20, 49, 1, 19, 55, 47,
572 | 39, 26, 48, 39, 58, 2, 59, 60, 13, 2,
573 | 42, 21, 13, 14, 15, 2, 53, 16, 3, 17,
574 | 18, 23, 30, 31, 32, 33, 29, 8, 9, 24,
575 | 30, 31, 32, 33, 30, 31, 32, 33, -17, 35,
576 | -17, -17, 16, 56, 25, 18, 27, 28, 52, 57,
577 | 37, 41, 51
578 | };
579 |
580 | static const yytype_uint8 yycheck[] =
581 | {
582 | 4, 4, 29, 3, 5, 0, 1, 5, 8, 24,
583 | 1, 3, 21, 3, 7, 5, 1, 5, 10, 10,
584 | 21, 5, 3, 21, 5, 20, 53, 54, 23, 20,
585 | 1, 9, 23, 37, 37, 20, 6, 3, 23, 5,
586 | 6, 24, 13, 14, 15, 16, 9, 21, 22, 21,
587 | 13, 14, 15, 16, 13, 14, 15, 16, 3, 20,
588 | 5, 6, 3, 20, 5, 6, 21, 22, 24, 21,
589 | 21, 24, 41
590 | };
591 |
592 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
593 | symbol of state STATE-NUM. */
594 | static const yytype_uint8 yystos[] =
595 | {
596 | 0, 1, 20, 23, 26, 27, 31, 24, 21, 22,
597 | 21, 0, 1, 23, 27, 31, 3, 5, 6, 5,
598 | 7, 9, 30, 24, 21, 5, 5, 21, 22, 9,
599 | 13, 14, 15, 16, 28, 20, 33, 26, 5, 21,
600 | 32, 30, 1, 28, 29, 3, 8, 10, 3, 5,
601 | 5, 32, 24, 6, 3, 10, 20, 21, 5, 28,
602 | 28
603 | };
604 |
605 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
606 | static const yytype_uint8 yyr1[] =
607 | {
608 | 0, 25, 26, 26, 26, 26, 26, 26, 26, 26,
609 | 26, 27, 27, 27, 27, 27, 27, 27, 28, 28,
610 | 28, 28, 29, 29, 29, 29, 30, 31, 32, 32,
611 | 33, 33
612 | };
613 |
614 | /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
615 | static const yytype_uint8 yyr2[] =
616 | {
617 | 0, 2, 2, 2, 4, 5, 3, 3, 5, 6,
618 | 2, 2, 3, 3, 2, 5, 3, 2, 1, 1,
619 | 1, 1, 1, 3, 3, 2, 3, 5, 1, 3,
620 | 1, 3
621 | };
622 |
623 |
624 | #define yyerrok (yyerrstatus = 0)
625 | #define yyclearin (yychar = YYEMPTY)
626 | #define YYEMPTY (-2)
627 | #define YYEOF 0
628 |
629 | #define YYACCEPT goto yyacceptlab
630 | #define YYABORT goto yyabortlab
631 | #define YYERROR goto yyerrorlab
632 |
633 |
634 | #define YYRECOVERING() (!!yyerrstatus)
635 |
636 | #define YYBACKUP(Token, Value) \
637 | do \
638 | if (yychar == YYEMPTY) \
639 | { \
640 | yychar = (Token); \
641 | yylval = (Value); \
642 | YYPOPSTACK (yylen); \
643 | yystate = *yyssp; \
644 | YY_LAC_DISCARD ("YYBACKUP"); \
645 | goto yybackup; \
646 | } \
647 | else \
648 | { \
649 | yyerror (YY_("syntax error: cannot back up")); \
650 | YYERROR; \
651 | } \
652 | while (0)
653 |
654 | /* Error token number */
655 | #define YYTERROR 1
656 | #define YYERRCODE 256
657 |
658 |
659 |
660 | /* Enable debugging if requested. */
661 | #if YYDEBUG
662 |
663 | # ifndef YYFPRINTF
664 | # include /* INFRINGES ON USER NAME SPACE */
665 | # define YYFPRINTF fprintf
666 | # endif
667 |
668 | # define YYDPRINTF(Args) \
669 | do { \
670 | if (yydebug) \
671 | YYFPRINTF Args; \
672 | } while (0)
673 |
674 | /* This macro is provided for backward compatibility. */
675 | #ifndef YY_LOCATION_PRINT
676 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
677 | #endif
678 |
679 |
680 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
681 | do { \
682 | if (yydebug) \
683 | { \
684 | YYFPRINTF (stderr, "%s ", Title); \
685 | yy_symbol_print (stderr, \
686 | Type, Value); \
687 | YYFPRINTF (stderr, "\n"); \
688 | } \
689 | } while (0)
690 |
691 |
692 | /*----------------------------------------.
693 | | Print this symbol's value on YYOUTPUT. |
694 | `----------------------------------------*/
695 |
696 | static void
697 | yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
698 | {
699 | FILE *yyo = yyoutput;
700 | YYUSE (yyo);
701 | if (!yyvaluep)
702 | return;
703 | # ifdef YYPRINT
704 | if (yytype < YYNTOKENS)
705 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
706 | # endif
707 | YYUSE (yytype);
708 | }
709 |
710 |
711 | /*--------------------------------.
712 | | Print this symbol on YYOUTPUT. |
713 | `--------------------------------*/
714 |
715 | static void
716 | yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
717 | {
718 | YYFPRINTF (yyoutput, "%s %s (",
719 | yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
720 |
721 | yy_symbol_value_print (yyoutput, yytype, yyvaluep);
722 | YYFPRINTF (yyoutput, ")");
723 | }
724 |
725 | /*------------------------------------------------------------------.
726 | | yy_stack_print -- Print the state stack from its BOTTOM up to its |
727 | | TOP (included). |
728 | `------------------------------------------------------------------*/
729 |
730 | static void
731 | yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
732 | {
733 | YYFPRINTF (stderr, "Stack now");
734 | for (; yybottom <= yytop; yybottom++)
735 | {
736 | int yybot = *yybottom;
737 | YYFPRINTF (stderr, " %d", yybot);
738 | }
739 | YYFPRINTF (stderr, "\n");
740 | }
741 |
742 | # define YY_STACK_PRINT(Bottom, Top) \
743 | do { \
744 | if (yydebug) \
745 | yy_stack_print ((Bottom), (Top)); \
746 | } while (0)
747 |
748 |
749 | /*------------------------------------------------.
750 | | Report that the YYRULE is going to be reduced. |
751 | `------------------------------------------------*/
752 |
753 | static void
754 | yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
755 | {
756 | unsigned long int yylno = yyrline[yyrule];
757 | int yynrhs = yyr2[yyrule];
758 | int yyi;
759 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
760 | yyrule - 1, yylno);
761 | /* The symbols being reduced. */
762 | for (yyi = 0; yyi < yynrhs; yyi++)
763 | {
764 | YYFPRINTF (stderr, " $%d = ", yyi + 1);
765 | yy_symbol_print (stderr,
766 | yystos[yyssp[yyi + 1 - yynrhs]],
767 | &(yyvsp[(yyi + 1) - (yynrhs)])
768 | );
769 | YYFPRINTF (stderr, "\n");
770 | }
771 | }
772 |
773 | # define YY_REDUCE_PRINT(Rule) \
774 | do { \
775 | if (yydebug) \
776 | yy_reduce_print (yyssp, yyvsp, Rule); \
777 | } while (0)
778 |
779 | /* Nonzero means print parse trace. It is left uninitialized so that
780 | multiple parsers can coexist. */
781 | int yydebug;
782 | #else /* !YYDEBUG */
783 | # define YYDPRINTF(Args)
784 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
785 | # define YY_STACK_PRINT(Bottom, Top)
786 | # define YY_REDUCE_PRINT(Rule)
787 | #endif /* !YYDEBUG */
788 |
789 |
790 | /* YYINITDEPTH -- initial size of the parser's stacks. */
791 | #ifndef YYINITDEPTH
792 | # define YYINITDEPTH 200
793 | #endif
794 |
795 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
796 | if the built-in stack extension method is used).
797 |
798 | Do not make this value too large; the results are undefined if
799 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
800 | evaluated with infinite-precision integer arithmetic. */
801 |
802 | #ifndef YYMAXDEPTH
803 | # define YYMAXDEPTH 10000
804 | #endif
805 |
806 | /* Given a state stack such that *YYBOTTOM is its bottom, such that
807 | *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty
808 | stack, and such that *YYCAPACITY is the maximum number of elements it
809 | can hold without a reallocation, make sure there is enough room to
810 | store YYADD more elements. If not, allocate a new stack using
811 | YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM,
812 | *YYTOP, and *YYCAPACITY to reflect the new capacity and memory
813 | location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack
814 | using YYSTACK_FREE. Return 0 if successful or if no reallocation is
815 | required. Return 1 if memory is exhausted. */
816 | static int
817 | yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
818 | #if YYDEBUG
819 | char const *yydebug_prefix,
820 | char const *yydebug_suffix,
821 | #endif
822 | yytype_int16 **yybottom,
823 | yytype_int16 *yybottom_no_free,
824 | yytype_int16 **yytop, yytype_int16 *yytop_empty)
825 | {
826 | YYSIZE_T yysize_old =
827 | *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
828 | YYSIZE_T yysize_new = yysize_old + yyadd;
829 | if (*yycapacity < yysize_new)
830 | {
831 | YYSIZE_T yyalloc = 2 * yysize_new;
832 | yytype_int16 *yybottom_new;
833 | /* Use YYMAXDEPTH for maximum stack size given that the stack
834 | should never need to grow larger than the main state stack
835 | needs to grow without LAC. */
836 | if (YYMAXDEPTH < yysize_new)
837 | {
838 | YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix,
839 | yydebug_suffix));
840 | return 1;
841 | }
842 | if (YYMAXDEPTH < yyalloc)
843 | yyalloc = YYMAXDEPTH;
844 | yybottom_new =
845 | (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new);
846 | if (!yybottom_new)
847 | {
848 | YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
849 | yydebug_suffix));
850 | return 1;
851 | }
852 | if (*yytop != yytop_empty)
853 | {
854 | YYCOPY (yybottom_new, *yybottom, yysize_old);
855 | *yytop = yybottom_new + (yysize_old - 1);
856 | }
857 | if (*yybottom != yybottom_no_free)
858 | YYSTACK_FREE (*yybottom);
859 | *yybottom = yybottom_new;
860 | *yycapacity = yyalloc;
861 | }
862 | return 0;
863 | }
864 |
865 | /* Establish the initial context for the current lookahead if no initial
866 | context is currently established.
867 |
868 | We define a context as a snapshot of the parser stacks. We define
869 | the initial context for a lookahead as the context in which the
870 | parser initially examines that lookahead in order to select a
871 | syntactic action. Thus, if the lookahead eventually proves
872 | syntactically unacceptable (possibly in a later context reached via a
873 | series of reductions), the initial context can be used to determine
874 | the exact set of tokens that would be syntactically acceptable in the
875 | lookahead's place. Moreover, it is the context after which any
876 | further semantic actions would be erroneous because they would be
877 | determined by a syntactically unacceptable token.
878 |
879 | YY_LAC_ESTABLISH should be invoked when a reduction is about to be
880 | performed in an inconsistent state (which, for the purposes of LAC,
881 | includes consistent states that don't know they're consistent because
882 | their default reductions have been disabled). Iff there is a
883 | lookahead token, it should also be invoked before reporting a syntax
884 | error. This latter case is for the sake of the debugging output.
885 |
886 | For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as
887 | follows. If no initial context is currently established for the
888 | current lookahead, then check if that lookahead can eventually be
889 | shifted if syntactic actions continue from the current context.
890 | Report a syntax error if it cannot. */
891 | #define YY_LAC_ESTABLISH \
892 | do { \
893 | if (!yy_lac_established) \
894 | { \
895 | YYDPRINTF ((stderr, \
896 | "LAC: initial context established for %s\n", \
897 | yytname[yytoken])); \
898 | yy_lac_established = 1; \
899 | { \
900 | int yy_lac_status = \
901 | yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken); \
902 | if (yy_lac_status == 2) \
903 | goto yyexhaustedlab; \
904 | if (yy_lac_status == 1) \
905 | goto yyerrlab; \
906 | } \
907 | } \
908 | } while (0)
909 |
910 | /* Discard any previous initial lookahead context because of Event,
911 | which may be a lookahead change or an invalidation of the currently
912 | established initial context for the current lookahead.
913 |
914 | The most common example of a lookahead change is a shift. An example
915 | of both cases is syntax error recovery. That is, a syntax error
916 | occurs when the lookahead is syntactically erroneous for the
917 | currently established initial context, so error recovery manipulates
918 | the parser stacks to try to find a new initial context in which the
919 | current lookahead is syntactically acceptable. If it fails to find
920 | such a context, it discards the lookahead. */
921 | #if YYDEBUG
922 | # define YY_LAC_DISCARD(Event) \
923 | do { \
924 | if (yy_lac_established) \
925 | { \
926 | if (yydebug) \
927 | YYFPRINTF (stderr, "LAC: initial context discarded due to " \
928 | Event "\n"); \
929 | yy_lac_established = 0; \
930 | } \
931 | } while (0)
932 | #else
933 | # define YY_LAC_DISCARD(Event) yy_lac_established = 0
934 | #endif
935 |
936 | /* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can
937 | eventually (after perhaps some reductions) be shifted, return 1 if
938 | not, or return 2 if memory is exhausted. As preconditions and
939 | postconditions: *YYES_CAPACITY is the allocated size of the array to
940 | which *YYES points, and either *YYES = YYESA or *YYES points to an
941 | array allocated with YYSTACK_ALLOC. yy_lac may overwrite the
942 | contents of either array, alter *YYES and *YYES_CAPACITY, and free
943 | any old *YYES other than YYESA. */
944 | static int
945 | yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
946 | YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
947 | {
948 | yytype_int16 *yyes_prev = yyssp;
949 | yytype_int16 *yyesp = yyes_prev;
950 | YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken]));
951 | if (yytoken == YYUNDEFTOK)
952 | {
953 | YYDPRINTF ((stderr, " Always Err\n"));
954 | return 1;
955 | }
956 | while (1)
957 | {
958 | int yyrule = yypact[*yyesp];
959 | if (yypact_value_is_default (yyrule)
960 | || (yyrule += yytoken) < 0 || YYLAST < yyrule
961 | || yycheck[yyrule] != yytoken)
962 | {
963 | yyrule = yydefact[*yyesp];
964 | if (yyrule == 0)
965 | {
966 | YYDPRINTF ((stderr, " Err\n"));
967 | return 1;
968 | }
969 | }
970 | else
971 | {
972 | yyrule = yytable[yyrule];
973 | if (yytable_value_is_error (yyrule))
974 | {
975 | YYDPRINTF ((stderr, " Err\n"));
976 | return 1;
977 | }
978 | if (0 < yyrule)
979 | {
980 | YYDPRINTF ((stderr, " S%d\n", yyrule));
981 | return 0;
982 | }
983 | yyrule = -yyrule;
984 | }
985 | {
986 | YYSIZE_T yylen = yyr2[yyrule];
987 | YYDPRINTF ((stderr, " R%d", yyrule - 1));
988 | if (yyesp != yyes_prev)
989 | {
990 | YYSIZE_T yysize = yyesp - *yyes + 1;
991 | if (yylen < yysize)
992 | {
993 | yyesp -= yylen;
994 | yylen = 0;
995 | }
996 | else
997 | {
998 | yylen -= yysize;
999 | yyesp = yyes_prev;
1000 | }
1001 | }
1002 | if (yylen)
1003 | yyesp = yyes_prev -= yylen;
1004 | }
1005 | {
1006 | int yystate;
1007 | {
1008 | int yylhs = yyr1[yyrule] - YYNTOKENS;
1009 | yystate = yypgoto[yylhs] + *yyesp;
1010 | if (yystate < 0 || YYLAST < yystate
1011 | || yycheck[yystate] != *yyesp)
1012 | yystate = yydefgoto[yylhs];
1013 | else
1014 | yystate = yytable[yystate];
1015 | }
1016 | if (yyesp == yyes_prev)
1017 | {
1018 | yyesp = *yyes;
1019 | *yyesp = yystate;
1020 | }
1021 | else
1022 | {
1023 | if (yy_lac_stack_realloc (yyes_capacity, 1,
1024 | #if YYDEBUG
1025 | " (", ")",
1026 | #endif
1027 | yyes, yyesa, &yyesp, yyes_prev))
1028 | {
1029 | YYDPRINTF ((stderr, "\n"));
1030 | return 2;
1031 | }
1032 | *++yyesp = yystate;
1033 | }
1034 | YYDPRINTF ((stderr, " G%d", yystate));
1035 | }
1036 | }
1037 | }
1038 |
1039 |
1040 | #if YYERROR_VERBOSE
1041 |
1042 | # ifndef yystrlen
1043 | # if defined __GLIBC__ && defined _STRING_H
1044 | # define yystrlen strlen
1045 | # else
1046 | /* Return the length of YYSTR. */
1047 | static YYSIZE_T
1048 | yystrlen (const char *yystr)
1049 | {
1050 | YYSIZE_T yylen;
1051 | for (yylen = 0; yystr[yylen]; yylen++)
1052 | continue;
1053 | return yylen;
1054 | }
1055 | # endif
1056 | # endif
1057 |
1058 | # ifndef yystpcpy
1059 | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1060 | # define yystpcpy stpcpy
1061 | # else
1062 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1063 | YYDEST. */
1064 | static char *
1065 | yystpcpy (char *yydest, const char *yysrc)
1066 | {
1067 | char *yyd = yydest;
1068 | const char *yys = yysrc;
1069 |
1070 | while ((*yyd++ = *yys++) != '\0')
1071 | continue;
1072 |
1073 | return yyd - 1;
1074 | }
1075 | # endif
1076 | # endif
1077 |
1078 | # ifndef yytnamerr
1079 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1080 | quotes and backslashes, so that it's suitable for yyerror. The
1081 | heuristic is that double-quoting is unnecessary unless the string
1082 | contains an apostrophe, a comma, or backslash (other than
1083 | backslash-backslash). YYSTR is taken from yytname. If YYRES is
1084 | null, do not copy; instead, return the length of what the result
1085 | would have been. */
1086 | static YYSIZE_T
1087 | yytnamerr (char *yyres, const char *yystr)
1088 | {
1089 | if (*yystr == '"')
1090 | {
1091 | YYSIZE_T yyn = 0;
1092 | char const *yyp = yystr;
1093 |
1094 | for (;;)
1095 | switch (*++yyp)
1096 | {
1097 | case '\'':
1098 | case ',':
1099 | goto do_not_strip_quotes;
1100 |
1101 | case '\\':
1102 | if (*++yyp != '\\')
1103 | goto do_not_strip_quotes;
1104 | /* Fall through. */
1105 | default:
1106 | if (yyres)
1107 | yyres[yyn] = *yyp;
1108 | yyn++;
1109 | break;
1110 |
1111 | case '"':
1112 | if (yyres)
1113 | yyres[yyn] = '\0';
1114 | return yyn;
1115 | }
1116 | do_not_strip_quotes: ;
1117 | }
1118 |
1119 | if (! yyres)
1120 | return yystrlen (yystr);
1121 |
1122 | return yystpcpy (yyres, yystr) - yyres;
1123 | }
1124 | # endif
1125 |
1126 | /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1127 | about the unexpected token YYTOKEN for the state stack whose top is
1128 | YYSSP. In order to see if a particular token T is a
1129 | valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).
1130 |
1131 | Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1132 | not large enough to hold the message. In that case, also set
1133 | *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1134 | required number of bytes is too large to store or if
1135 | yy_lac returned 2. */
1136 | static int
1137 | yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1138 | yytype_int16 *yyesa, yytype_int16 **yyes,
1139 | YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
1140 | {
1141 | YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1142 | YYSIZE_T yysize = yysize0;
1143 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1144 | /* Internationalized format string. */
1145 | const char *yyformat = YY_NULLPTR;
1146 | /* Arguments of yyformat. */
1147 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1148 | /* Number of reported tokens (one for the "unexpected", one per
1149 | "expected"). */
1150 | int yycount = 0;
1151 |
1152 | /* There are many possibilities here to consider:
1153 | - If this state is a consistent state with a default action, then
1154 | the only way this function was invoked is if the default action
1155 | is an error action. In that case, don't check for expected
1156 | tokens because there are none.
1157 | - The only way there can be no lookahead present (in yychar) is if
1158 | this state is a consistent state with a default action. Thus,
1159 | detecting the absence of a lookahead is sufficient to determine
1160 | that there is no unexpected or expected token to report. In that
1161 | case, just report a simple "syntax error".
1162 | - Don't assume there isn't a lookahead just because this state is a
1163 | consistent state with a default action. There might have been a
1164 | previous inconsistent state, consistent state with a non-default
1165 | action, or user semantic action that manipulated yychar.
1166 | In the first two cases, it might appear that the current syntax
1167 | error should have been detected in the previous state when yy_lac
1168 | was invoked. However, at that time, there might have been a
1169 | different syntax error that discarded a different initial context
1170 | during error recovery, leaving behind the current lookahead.
1171 | */
1172 | if (yytoken != YYEMPTY)
1173 | {
1174 | int yyn = yypact[*yyssp];
1175 | YYDPRINTF ((stderr, "Constructing syntax error message\n"));
1176 | yyarg[yycount++] = yytname[yytoken];
1177 | if (!yypact_value_is_default (yyn))
1178 | {
1179 | int yyx;
1180 |
1181 | for (yyx = 0; yyx < YYNTOKENS; ++yyx)
1182 | if (yyx != YYTERROR && yyx != YYUNDEFTOK)
1183 | {
1184 | {
1185 | int yy_lac_status = yy_lac (yyesa, yyes, yyes_capacity,
1186 | yyssp, yyx);
1187 | if (yy_lac_status == 2)
1188 | return 2;
1189 | if (yy_lac_status == 1)
1190 | continue;
1191 | }
1192 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1193 | {
1194 | yycount = 1;
1195 | yysize = yysize0;
1196 | break;
1197 | }
1198 | yyarg[yycount++] = yytname[yyx];
1199 | {
1200 | YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1201 | if (! (yysize <= yysize1
1202 | && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1203 | return 2;
1204 | yysize = yysize1;
1205 | }
1206 | }
1207 | }
1208 | # if YYDEBUG
1209 | else if (yydebug)
1210 | YYFPRINTF (stderr, "No expected tokens.\n");
1211 | # endif
1212 | }
1213 |
1214 | switch (yycount)
1215 | {
1216 | # define YYCASE_(N, S) \
1217 | case N: \
1218 | yyformat = S; \
1219 | break
1220 | YYCASE_(0, YY_("syntax error"));
1221 | YYCASE_(1, YY_("syntax error, unexpected %s"));
1222 | YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1223 | YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1224 | YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1225 | YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1226 | # undef YYCASE_
1227 | }
1228 |
1229 | {
1230 | YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1231 | if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1232 | return 2;
1233 | yysize = yysize1;
1234 | }
1235 |
1236 | if (*yymsg_alloc < yysize)
1237 | {
1238 | *yymsg_alloc = 2 * yysize;
1239 | if (! (yysize <= *yymsg_alloc
1240 | && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1241 | *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1242 | return 1;
1243 | }
1244 |
1245 | /* Avoid sprintf, as that infringes on the user's name space.
1246 | Don't have undefined behavior even if the translation
1247 | produced a string with the wrong number of "%s"s. */
1248 | {
1249 | char *yyp = *yymsg;
1250 | int yyi = 0;
1251 | while ((*yyp = *yyformat) != '\0')
1252 | if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1253 | {
1254 | yyp += yytnamerr (yyp, yyarg[yyi++]);
1255 | yyformat += 2;
1256 | }
1257 | else
1258 | {
1259 | yyp++;
1260 | yyformat++;
1261 | }
1262 | }
1263 | return 0;
1264 | }
1265 | #endif /* YYERROR_VERBOSE */
1266 |
1267 | /*-----------------------------------------------.
1268 | | Release the memory associated to this symbol. |
1269 | `-----------------------------------------------*/
1270 |
1271 | static void
1272 | yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1273 | {
1274 | YYUSE (yyvaluep);
1275 | if (!yymsg)
1276 | yymsg = "Deleting";
1277 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1278 |
1279 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1280 | YYUSE (yytype);
1281 | YY_IGNORE_MAYBE_UNINITIALIZED_END
1282 | }
1283 |
1284 |
1285 |
1286 |
1287 | /* The lookahead symbol. */
1288 | int yychar;
1289 |
1290 | /* The semantic value of the lookahead symbol. */
1291 | YYSTYPE yylval;
1292 | /* Number of syntax errors so far. */
1293 | int yynerrs;
1294 |
1295 |
1296 | /*----------.
1297 | | yyparse. |
1298 | `----------*/
1299 |
1300 | int
1301 | yyparse (void)
1302 | {
1303 | int yystate;
1304 | /* Number of tokens to shift before error messages enabled. */
1305 | int yyerrstatus;
1306 |
1307 | /* The stacks and their tools:
1308 | 'yyss': related to states.
1309 | 'yyvs': related to semantic values.
1310 |
1311 | Refer to the stacks through separate pointers, to allow yyoverflow
1312 | to reallocate them elsewhere. */
1313 |
1314 | /* The state stack. */
1315 | yytype_int16 yyssa[YYINITDEPTH];
1316 | yytype_int16 *yyss;
1317 | yytype_int16 *yyssp;
1318 |
1319 | /* The semantic value stack. */
1320 | YYSTYPE yyvsa[YYINITDEPTH];
1321 | YYSTYPE *yyvs;
1322 | YYSTYPE *yyvsp;
1323 |
1324 | YYSIZE_T yystacksize;
1325 |
1326 | yytype_int16 yyesa[20];
1327 | yytype_int16 *yyes;
1328 | YYSIZE_T yyes_capacity;
1329 |
1330 | int yy_lac_established = 0;
1331 | int yyn;
1332 | int yyresult;
1333 | /* Lookahead token as an internal (translated) token number. */
1334 | int yytoken = 0;
1335 | /* The variables used to return semantic value and location from the
1336 | action routines. */
1337 | YYSTYPE yyval;
1338 |
1339 | #if YYERROR_VERBOSE
1340 | /* Buffer for error messages, and its allocated size. */
1341 | char yymsgbuf[128];
1342 | char *yymsg = yymsgbuf;
1343 | YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1344 | #endif
1345 |
1346 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1347 |
1348 | /* The number of symbols on the RHS of the reduced rule.
1349 | Keep to zero when no symbol should be popped. */
1350 | int yylen = 0;
1351 |
1352 | yyssp = yyss = yyssa;
1353 | yyvsp = yyvs = yyvsa;
1354 | yystacksize = YYINITDEPTH;
1355 |
1356 | yyes = yyesa;
1357 | yyes_capacity = sizeof yyesa / sizeof *yyes;
1358 | if (YYMAXDEPTH < yyes_capacity)
1359 | yyes_capacity = YYMAXDEPTH;
1360 |
1361 | YYDPRINTF ((stderr, "Starting parse\n"));
1362 |
1363 | yystate = 0;
1364 | yyerrstatus = 0;
1365 | yynerrs = 0;
1366 | yychar = YYEMPTY; /* Cause a token to be read. */
1367 | goto yysetstate;
1368 |
1369 | /*------------------------------------------------------------.
1370 | | yynewstate -- Push a new state, which is found in yystate. |
1371 | `------------------------------------------------------------*/
1372 | yynewstate:
1373 | /* In all cases, when you get here, the value and location stacks
1374 | have just been pushed. So pushing a state here evens the stacks. */
1375 | yyssp++;
1376 |
1377 | yysetstate:
1378 | *yyssp = yystate;
1379 |
1380 | if (yyss + yystacksize - 1 <= yyssp)
1381 | {
1382 | /* Get the current used size of the three stacks, in elements. */
1383 | YYSIZE_T yysize = yyssp - yyss + 1;
1384 |
1385 | #ifdef yyoverflow
1386 | {
1387 | /* Give user a chance to reallocate the stack. Use copies of
1388 | these so that the &'s don't force the real ones into
1389 | memory. */
1390 | YYSTYPE *yyvs1 = yyvs;
1391 | yytype_int16 *yyss1 = yyss;
1392 |
1393 | /* Each stack pointer address is followed by the size of the
1394 | data in use in that stack, in bytes. This used to be a
1395 | conditional around just the two extra args, but that might
1396 | be undefined if yyoverflow is a macro. */
1397 | yyoverflow (YY_("memory exhausted"),
1398 | &yyss1, yysize * sizeof (*yyssp),
1399 | &yyvs1, yysize * sizeof (*yyvsp),
1400 | &yystacksize);
1401 |
1402 | yyss = yyss1;
1403 | yyvs = yyvs1;
1404 | }
1405 | #else /* no yyoverflow */
1406 | # ifndef YYSTACK_RELOCATE
1407 | goto yyexhaustedlab;
1408 | # else
1409 | /* Extend the stack our own way. */
1410 | if (YYMAXDEPTH <= yystacksize)
1411 | goto yyexhaustedlab;
1412 | yystacksize *= 2;
1413 | if (YYMAXDEPTH < yystacksize)
1414 | yystacksize = YYMAXDEPTH;
1415 |
1416 | {
1417 | yytype_int16 *yyss1 = yyss;
1418 | union yyalloc *yyptr =
1419 | (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1420 | if (! yyptr)
1421 | goto yyexhaustedlab;
1422 | YYSTACK_RELOCATE (yyss_alloc, yyss);
1423 | YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1424 | # undef YYSTACK_RELOCATE
1425 | if (yyss1 != yyssa)
1426 | YYSTACK_FREE (yyss1);
1427 | }
1428 | # endif
1429 | #endif /* no yyoverflow */
1430 |
1431 | yyssp = yyss + yysize - 1;
1432 | yyvsp = yyvs + yysize - 1;
1433 |
1434 | YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1435 | (unsigned long int) yystacksize));
1436 |
1437 | if (yyss + yystacksize - 1 <= yyssp)
1438 | YYABORT;
1439 | }
1440 |
1441 | YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1442 |
1443 | if (yystate == YYFINAL)
1444 | YYACCEPT;
1445 |
1446 | goto yybackup;
1447 |
1448 | /*-----------.
1449 | | yybackup. |
1450 | `-----------*/
1451 | yybackup:
1452 |
1453 | /* Do appropriate processing given the current state. Read a
1454 | lookahead token if we need one and don't already have one. */
1455 |
1456 | /* First try to decide what to do without reference to lookahead token. */
1457 | yyn = yypact[yystate];
1458 | if (yypact_value_is_default (yyn))
1459 | goto yydefault;
1460 |
1461 | /* Not known => get a lookahead token if don't already have one. */
1462 |
1463 | /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1464 | if (yychar == YYEMPTY)
1465 | {
1466 | YYDPRINTF ((stderr, "Reading a token: "));
1467 | yychar = yylex ();
1468 | }
1469 |
1470 | if (yychar <= YYEOF)
1471 | {
1472 | yychar = yytoken = YYEOF;
1473 | YYDPRINTF ((stderr, "Now at end of input.\n"));
1474 | }
1475 | else
1476 | {
1477 | yytoken = YYTRANSLATE (yychar);
1478 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1479 | }
1480 |
1481 | /* If the proper action on seeing token YYTOKEN is to reduce or to
1482 | detect an error, take that action. */
1483 | yyn += yytoken;
1484 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1485 | {
1486 | YY_LAC_ESTABLISH;
1487 | goto yydefault;
1488 | }
1489 | yyn = yytable[yyn];
1490 | if (yyn <= 0)
1491 | {
1492 | if (yytable_value_is_error (yyn))
1493 | goto yyerrlab;
1494 | YY_LAC_ESTABLISH;
1495 | yyn = -yyn;
1496 | goto yyreduce;
1497 | }
1498 |
1499 | /* Count tokens shifted since error; after three, turn off error
1500 | status. */
1501 | if (yyerrstatus)
1502 | yyerrstatus--;
1503 |
1504 | /* Shift the lookahead token. */
1505 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1506 |
1507 | /* Discard the shifted token. */
1508 | yychar = YYEMPTY;
1509 | YY_LAC_DISCARD ("shift");
1510 |
1511 | yystate = yyn;
1512 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1513 | *++yyvsp = yylval;
1514 | YY_IGNORE_MAYBE_UNINITIALIZED_END
1515 |
1516 | goto yynewstate;
1517 |
1518 |
1519 | /*-----------------------------------------------------------.
1520 | | yydefault -- do the default action for the current state. |
1521 | `-----------------------------------------------------------*/
1522 | yydefault:
1523 | yyn = yydefact[yystate];
1524 | if (yyn == 0)
1525 | goto yyerrlab;
1526 | goto yyreduce;
1527 |
1528 |
1529 | /*-----------------------------.
1530 | | yyreduce -- Do a reduction. |
1531 | `-----------------------------*/
1532 | yyreduce:
1533 | /* yyn is the number of a rule to reduce with. */
1534 | yylen = yyr2[yyn];
1535 |
1536 | /* If YYLEN is nonzero, implement the default value of the action:
1537 | '$$ = $1'.
1538 |
1539 | Otherwise, the following line sets YYVAL to garbage.
1540 | This behavior is undocumented and Bison
1541 | users should not rely upon it. Assigning to YYVAL
1542 | unconditionally makes the parser a bit smaller, and it avoids a
1543 | GCC warning that YYVAL may be used uninitialized. */
1544 | yyval = yyvsp[1-yylen];
1545 |
1546 |
1547 | YY_REDUCE_PRINT (yyn);
1548 | {
1549 | int yychar_backup = yychar;
1550 | switch (yyn)
1551 | {
1552 | case 2:
1553 | #line 70 "syntax2.y" /* yacc.c:1646 */
1554 | { clearBuffers(); }
1555 | #line 1556 "y.tab.c" /* yacc.c:1646 */
1556 | break;
1557 |
1558 | case 6:
1559 | #line 74 "syntax2.y" /* yacc.c:1646 */
1560 | { clearBuffers(); }
1561 | #line 1562 "y.tab.c" /* yacc.c:1646 */
1562 | break;
1563 |
1564 | case 10:
1565 | #line 79 "syntax2.y" /* yacc.c:1646 */
1566 | {/* ' > ' stops execution all together */}
1567 | #line 1568 "y.tab.c" /* yacc.c:1646 */
1568 | break;
1569 |
1570 | case 11:
1571 | #line 82 "syntax2.y" /* yacc.c:1646 */
1572 | {
1573 | if(!isDuplicate((yyvsp[0].strVal),retrieveDataType())){
1574 | storeIdentifier((yyvsp[0].strVal),retrieveDataType());
1575 | storeDataType((yyvsp[-1].dataType));
1576 | }else{
1577 | DuplicateIdentifierError((yyvsp[0].strVal));
1578 | }
1579 | }
1580 | #line 1581 "y.tab.c" /* yacc.c:1646 */
1581 | break;
1582 |
1583 | case 12:
1584 | #line 93 "syntax2.y" /* yacc.c:1646 */
1585 | {;}
1586 | #line 1587 "y.tab.c" /* yacc.c:1646 */
1587 | break;
1588 |
1589 | case 13:
1590 | #line 95 "syntax2.y" /* yacc.c:1646 */
1591 | {
1592 | if(!isDuplicate((yyvsp[0].strVal),retrieveDataType())){
1593 | storeIdentifier((yyvsp[0].strVal),retrieveDataType());
1594 | }else{
1595 | DuplicateIdentifierError((yyvsp[0].strVal));
1596 | }
1597 | }
1598 | #line 1599 "y.tab.c" /* yacc.c:1646 */
1599 | break;
1600 |
1601 | case 14:
1602 | #line 106 "syntax2.y" /* yacc.c:1646 */
1603 | {
1604 |
1605 | strcpy(extractedIdentifier[noOfArrayIdentifiers],extractIdentifier((yyvsp[0].strVal)));
1606 | if(!isDuplicate(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType())){
1607 | storeIdentifier(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType());
1608 | storeDataType((yyvsp[-1].dataType));
1609 | }else{
1610 | DuplicateIdentifierError(extractedIdentifier[noOfArrayIdentifiers]);
1611 | }
1612 | noOfArrayIdentifiers++;
1613 | }
1614 | #line 1615 "y.tab.c" /* yacc.c:1646 */
1615 | break;
1616 |
1617 | case 16:
1618 | #line 120 "syntax2.y" /* yacc.c:1646 */
1619 | {
1620 | strcpy(extractedIdentifier[noOfArrayIdentifiers],extractIdentifier((yyvsp[0].strVal)));
1621 | if(!isDuplicate(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType())){
1622 | storeIdentifier(extractedIdentifier[noOfArrayIdentifiers],retrieveDataType());
1623 | }else{
1624 | DuplicateIdentifierError(extractedIdentifier[noOfArrayIdentifiers]);
1625 | }
1626 | noOfArrayIdentifiers++;
1627 | }
1628 | #line 1629 "y.tab.c" /* yacc.c:1646 */
1629 | break;
1630 |
1631 | case 17:
1632 | #line 131 "syntax2.y" /* yacc.c:1646 */
1633 | {/* no need to call yyerror cuz of line 1570 of y.tab.c*/}
1634 | #line 1635 "y.tab.c" /* yacc.c:1646 */
1635 | break;
1636 |
1637 | case 18:
1638 | #line 135 "syntax2.y" /* yacc.c:1646 */
1639 | {if(!isValidAssignment("int")){ AssignmentError(itoa((yyvsp[0].intVal)));}}
1640 | #line 1641 "y.tab.c" /* yacc.c:1646 */
1641 | break;
1642 |
1643 | case 19:
1644 | #line 136 "syntax2.y" /* yacc.c:1646 */
1645 | {if(!isValidAssignment("float")){ AssignmentError(ftoa((yyvsp[0].floatVal)));}}
1646 | #line 1647 "y.tab.c" /* yacc.c:1646 */
1647 | break;
1648 |
1649 | case 20:
1650 | #line 137 "syntax2.y" /* yacc.c:1646 */
1651 | {if(!isValidAssignment("char")){ AssignmentError(ctoa((yyvsp[0].charVal)));} }
1652 | #line 1653 "y.tab.c" /* yacc.c:1646 */
1653 | break;
1654 |
1655 | case 21:
1656 | #line 138 "syntax2.y" /* yacc.c:1646 */
1657 | {if(!isValidAssignment("char*")){ AssignmentError((yyvsp[0].strVal));} }
1658 | #line 1659 "y.tab.c" /* yacc.c:1646 */
1659 | break;
1660 |
1661 | case 24:
1662 | #line 144 "syntax2.y" /* yacc.c:1646 */
1663 | { yyerror("Two or more equal signs are not allowed in C");}
1664 | #line 1665 "y.tab.c" /* yacc.c:1646 */
1665 | break;
1666 |
1667 | case 27:
1668 | #line 152 "syntax2.y" /* yacc.c:1646 */
1669 | {
1670 |
1671 | if(!isDuplicate((yyvsp[-3].strVal),retrieveDataType())){
1672 | storeIdentifier((yyvsp[-3].strVal),retrieveDataType());
1673 | storeDataType((yyvsp[-4].dataType));
1674 | }else{
1675 | DuplicateIdentifierError((yyvsp[-3].strVal));
1676 | }
1677 |
1678 | }
1679 | #line 1680 "y.tab.c" /* yacc.c:1646 */
1680 | break;
1681 |
1682 |
1683 | #line 1684 "y.tab.c" /* yacc.c:1646 */
1684 | default: break;
1685 | }
1686 | if (yychar_backup != yychar)
1687 | YY_LAC_DISCARD ("yychar change");
1688 | }
1689 | /* User semantic actions sometimes alter yychar, and that requires
1690 | that yytoken be updated with the new translation. We take the
1691 | approach of translating immediately before every use of yytoken.
1692 | One alternative is translating here after every semantic action,
1693 | but that translation would be missed if the semantic action invokes
1694 | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1695 | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1696 | incorrect destructor might then be invoked immediately. In the
1697 | case of YYERROR or YYBACKUP, subsequent parser actions might lead
1698 | to an incorrect destructor call or verbose syntax error message
1699 | before the lookahead is translated. */
1700 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1701 |
1702 | YYPOPSTACK (yylen);
1703 | yylen = 0;
1704 | YY_STACK_PRINT (yyss, yyssp);
1705 |
1706 | *++yyvsp = yyval;
1707 |
1708 | /* Now 'shift' the result of the reduction. Determine what state
1709 | that goes to, based on the state we popped back to and the rule
1710 | number reduced by. */
1711 |
1712 | yyn = yyr1[yyn];
1713 |
1714 | yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1715 | if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1716 | yystate = yytable[yystate];
1717 | else
1718 | yystate = yydefgoto[yyn - YYNTOKENS];
1719 |
1720 | goto yynewstate;
1721 |
1722 |
1723 | /*--------------------------------------.
1724 | | yyerrlab -- here on detecting error. |
1725 | `--------------------------------------*/
1726 | yyerrlab:
1727 | /* Make sure we have latest lookahead translation. See comments at
1728 | user semantic actions for why this is necessary. */
1729 | yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1730 |
1731 | /* If not already recovering from an error, report this error. */
1732 | if (!yyerrstatus)
1733 | {
1734 | ++yynerrs;
1735 | #if ! YYERROR_VERBOSE
1736 | yyerror (YY_("syntax error"));
1737 | #else
1738 | # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1739 | yyesa, &yyes, &yyes_capacity, \
1740 | yyssp, yytoken)
1741 | {
1742 | char const *yymsgp = YY_("syntax error");
1743 | int yysyntax_error_status;
1744 | if (yychar != YYEMPTY)
1745 | YY_LAC_ESTABLISH;
1746 | yysyntax_error_status = YYSYNTAX_ERROR;
1747 | if (yysyntax_error_status == 0)
1748 | yymsgp = yymsg;
1749 | else if (yysyntax_error_status == 1)
1750 | {
1751 | if (yymsg != yymsgbuf)
1752 | YYSTACK_FREE (yymsg);
1753 | yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1754 | if (!yymsg)
1755 | {
1756 | yymsg = yymsgbuf;
1757 | yymsg_alloc = sizeof yymsgbuf;
1758 | yysyntax_error_status = 2;
1759 | }
1760 | else
1761 | {
1762 | yysyntax_error_status = YYSYNTAX_ERROR;
1763 | yymsgp = yymsg;
1764 | }
1765 | }
1766 | yyerror (yymsgp);
1767 | if (yysyntax_error_status == 2)
1768 | goto yyexhaustedlab;
1769 | }
1770 | # undef YYSYNTAX_ERROR
1771 | #endif
1772 | }
1773 |
1774 |
1775 |
1776 | if (yyerrstatus == 3)
1777 | {
1778 | /* If just tried and failed to reuse lookahead token after an
1779 | error, discard it. */
1780 |
1781 | if (yychar <= YYEOF)
1782 | {
1783 | /* Return failure if at end of input. */
1784 | if (yychar == YYEOF)
1785 | YYABORT;
1786 | }
1787 | else
1788 | {
1789 | yydestruct ("Error: discarding",
1790 | yytoken, &yylval);
1791 | yychar = YYEMPTY;
1792 | }
1793 | }
1794 |
1795 | /* Else will try to reuse lookahead token after shifting the error
1796 | token. */
1797 | goto yyerrlab1;
1798 |
1799 |
1800 | /*---------------------------------------------------.
1801 | | yyerrorlab -- error raised explicitly by YYERROR. |
1802 | `---------------------------------------------------*/
1803 | yyerrorlab:
1804 |
1805 | /* Pacify compilers like GCC when the user code never invokes
1806 | YYERROR and the label yyerrorlab therefore never appears in user
1807 | code. */
1808 | if (/*CONSTCOND*/ 0)
1809 | goto yyerrorlab;
1810 |
1811 | /* Do not reclaim the symbols of the rule whose action triggered
1812 | this YYERROR. */
1813 | YYPOPSTACK (yylen);
1814 | yylen = 0;
1815 | YY_STACK_PRINT (yyss, yyssp);
1816 | yystate = *yyssp;
1817 | goto yyerrlab1;
1818 |
1819 |
1820 | /*-------------------------------------------------------------.
1821 | | yyerrlab1 -- common code for both syntax error and YYERROR. |
1822 | `-------------------------------------------------------------*/
1823 | yyerrlab1:
1824 | yyerrstatus = 3; /* Each real token shifted decrements this. */
1825 |
1826 | for (;;)
1827 | {
1828 | yyn = yypact[yystate];
1829 | if (!yypact_value_is_default (yyn))
1830 | {
1831 | yyn += YYTERROR;
1832 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1833 | {
1834 | yyn = yytable[yyn];
1835 | if (0 < yyn)
1836 | break;
1837 | }
1838 | }
1839 |
1840 | /* Pop the current state because it cannot handle the error token. */
1841 | if (yyssp == yyss)
1842 | YYABORT;
1843 |
1844 |
1845 | yydestruct ("Error: popping",
1846 | yystos[yystate], yyvsp);
1847 | YYPOPSTACK (1);
1848 | yystate = *yyssp;
1849 | YY_STACK_PRINT (yyss, yyssp);
1850 | }
1851 |
1852 | /* If the stack popping above didn't lose the initial context for the
1853 | current lookahead token, the shift below will for sure. */
1854 | YY_LAC_DISCARD ("error recovery");
1855 |
1856 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1857 | *++yyvsp = yylval;
1858 | YY_IGNORE_MAYBE_UNINITIALIZED_END
1859 |
1860 |
1861 | /* Shift the error token. */
1862 | YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1863 |
1864 | yystate = yyn;
1865 | goto yynewstate;
1866 |
1867 |
1868 | /*-------------------------------------.
1869 | | yyacceptlab -- YYACCEPT comes here. |
1870 | `-------------------------------------*/
1871 | yyacceptlab:
1872 | yyresult = 0;
1873 | goto yyreturn;
1874 |
1875 | /*-----------------------------------.
1876 | | yyabortlab -- YYABORT comes here. |
1877 | `-----------------------------------*/
1878 | yyabortlab:
1879 | yyresult = 1;
1880 | goto yyreturn;
1881 |
1882 | #if 1
1883 | /*-------------------------------------------------.
1884 | | yyexhaustedlab -- memory exhaustion comes here. |
1885 | `-------------------------------------------------*/
1886 | yyexhaustedlab:
1887 | yyerror (YY_("memory exhausted"));
1888 | yyresult = 2;
1889 | /* Fall through. */
1890 | #endif
1891 |
1892 | yyreturn:
1893 | if (yychar != YYEMPTY)
1894 | {
1895 | /* Make sure we have latest lookahead translation. See comments at
1896 | user semantic actions for why this is necessary. */
1897 | yytoken = YYTRANSLATE (yychar);
1898 | yydestruct ("Cleanup: discarding lookahead",
1899 | yytoken, &yylval);
1900 | }
1901 | /* Do not reclaim the symbols of the rule whose action triggered
1902 | this YYABORT or YYACCEPT. */
1903 | YYPOPSTACK (yylen);
1904 | YY_STACK_PRINT (yyss, yyssp);
1905 | while (yyssp != yyss)
1906 | {
1907 | yydestruct ("Cleanup: popping",
1908 | yystos[*yyssp], yyvsp);
1909 | YYPOPSTACK (1);
1910 | }
1911 | #ifndef yyoverflow
1912 | if (yyss != yyssa)
1913 | YYSTACK_FREE (yyss);
1914 | #endif
1915 | if (yyes != yyesa)
1916 | YYSTACK_FREE (yyes);
1917 | #if YYERROR_VERBOSE
1918 | if (yymsg != yymsgbuf)
1919 | YYSTACK_FREE (yymsg);
1920 | #endif
1921 | return yyresult;
1922 | }
1923 | #line 172 "syntax2.y" /* yacc.c:1906 */
1924 |
1925 |
1926 |
1927 | int main(){
1928 |
1929 | yyparse();
1930 | printf("No Errors!!\n");
1931 | return 0;
1932 | }
1933 |
--------------------------------------------------------------------------------
/y.tab.h:
--------------------------------------------------------------------------------
1 | /* A Bison parser, made by GNU Bison 3.0.4. */
2 |
3 | /* Bison interface for Yacc-like parsers in C
4 |
5 | Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see . */
19 |
20 | /* As a special exception, you may create a larger work that contains
21 | part or all of the Bison parser skeleton and distribute that work
22 | under terms of your choice, so long as that work isn't itself a
23 | parser generator using the skeleton or a modified version thereof
24 | as a parser skeleton. Alternatively, if you modify or redistribute
25 | the parser skeleton itself, you may (at your option) remove this
26 | special exception, which will cause the skeleton and the resulting
27 | Bison output files to be licensed under the GNU General Public
28 | License without this special exception.
29 |
30 | This special exception was added by the Free Software Foundation in
31 | version 2.2 of Bison. */
32 |
33 | #ifndef YY_YY_Y_TAB_H_INCLUDED
34 | # define YY_YY_Y_TAB_H_INCLUDED
35 | /* Debug traces. */
36 | #ifndef YYDEBUG
37 | # define YYDEBUG 0
38 | #endif
39 | #if YYDEBUG
40 | extern int yydebug;
41 | #endif
42 |
43 | /* Token type. */
44 | #ifndef YYTOKENTYPE
45 | # define YYTOKENTYPE
46 | enum yytokentype
47 | {
48 | COMMA = 258,
49 | SINGLE_QUOTES = 259,
50 | SEMI_COLON = 260,
51 | EQUALS = 261,
52 | BRACKET_OPEN = 262,
53 | BRACKET_CLOSE = 263,
54 | CURLY_BRACE_OPEN = 264,
55 | CURLY_BRACE_CLOSE = 265,
56 | BIG_BRACKET_OPEN = 266,
57 | BIG_BRACKET_CLOSE = 267,
58 | CHARACTER_VALUE = 268,
59 | INTEGER_VALUE = 269,
60 | FLOAT_VALUE = 270,
61 | STRING_VALUE = 271,
62 | INT = 272,
63 | FLOAT = 273,
64 | STRING = 274,
65 | DATA_TYPE = 275,
66 | IDENTIFIER = 276,
67 | ARRAY_IDENTIFIER = 277,
68 | STRUCT = 278
69 | };
70 | #endif
71 | /* Tokens. */
72 | #define COMMA 258
73 | #define SINGLE_QUOTES 259
74 | #define SEMI_COLON 260
75 | #define EQUALS 261
76 | #define BRACKET_OPEN 262
77 | #define BRACKET_CLOSE 263
78 | #define CURLY_BRACE_OPEN 264
79 | #define CURLY_BRACE_CLOSE 265
80 | #define BIG_BRACKET_OPEN 266
81 | #define BIG_BRACKET_CLOSE 267
82 | #define CHARACTER_VALUE 268
83 | #define INTEGER_VALUE 269
84 | #define FLOAT_VALUE 270
85 | #define STRING_VALUE 271
86 | #define INT 272
87 | #define FLOAT 273
88 | #define STRING 274
89 | #define DATA_TYPE 275
90 | #define IDENTIFIER 276
91 | #define ARRAY_IDENTIFIER 277
92 | #define STRUCT 278
93 |
94 | /* Value type. */
95 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
96 |
97 | union YYSTYPE
98 | {
99 | #line 36 "syntax2.y" /* yacc.c:1909 */
100 |
101 | int intVal;
102 | char* dataType;
103 | char* strVal;
104 | float floatVal;
105 | char charVal;
106 |
107 | #line 108 "y.tab.h" /* yacc.c:1909 */
108 | };
109 |
110 | typedef union YYSTYPE YYSTYPE;
111 | # define YYSTYPE_IS_TRIVIAL 1
112 | # define YYSTYPE_IS_DECLARED 1
113 | #endif
114 |
115 |
116 | extern YYSTYPE yylval;
117 |
118 | int yyparse (void);
119 |
120 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */
121 |
--------------------------------------------------------------------------------