Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include "lista4.tab.hpp"
- #include <stdlib.h>
- extern int yylex();
- %}
- %%
- "=" {return EQ;}
- "!=" {return NE;}
- "<" {return LT;}
- ">" {return GT;}
- ":=" {return ASSIGN;}
- ";" {return SEMICOLON;}
- "IF" {return IF;}
- "THEN" {return THEN;}
- "ELSE" {return ELSE;}
- "WHILE" {return WHILE;}
- "DO" {return DO;}
- "PRINT" {return PRINT;}
- "END" {return END;}
- [_a-z]+ {yylval.text = strdup(yytext); return IDENTIFIER;}
- [ \t]+
- [0-9]+ {
- yylval.var = atoi (yytext);
- return NUMBER;
- }
- [-+/^*'%'()] {
- return *yytext;
- }
- \n return RESULT;
- %%
- ---------------------------------------------------------
- %{
- extern "C"
- {
- int yyparse();
- int yylex(void);
- void yyerror(char *s){}
- int yywrap(void){return 1;}
- }
- #include <iostream>
- #include <vector>
- #include <string>
- #include <stdlib.h>
- #include <map>
- using namespace std;
- vector <string> instructions;
- // map <> vars;
- %}
- %union{
- char* text;
- int var;
- }
- %token EQ
- %token NE
- %token LT
- %token GT
- %token ASSIGN
- %token SEMICOLON
- %token IF
- %token THEN
- %token ELSE
- %token WHILE
- %token DO
- %token PRINT
- %token END
- %token <text> IDENTIFIER
- %token <var> NUMBER
- %token <var> RESULT
- %token READ
- %token WRITE
- %left '+' '-'
- %left '*' '/' '%'
- %right '^'
- %%
- //program: CONST cdeclarations VAR vdeclarations START commands END
- //;
- /*cdeclarations: cdeclarations IDENTIFIER EQ NUMBER
- |
- ;
- vdeclarations: vdeclarations IDENTIFIER
- |
- ;
- commands: commands command
- |
- ;*/
- /*command: IDENTIFIER ASSIGN exp SEMICOLON {}
- | IF condition THEN commands ELSE commands END
- | WHILE condition DO commands END
- | READ IDENTIFIER SEMICOLON
- | WRITE IDENTIFIER SEMICOLON
- ;*/
- exp: NUMBER
- | IDENTIFIER
- | IDENTIFIER "+" IDENTIFIER
- | IDENTIFIER "-" IDENTIFIER
- | IDENTIFIER "*" IDENTIFIER
- | IDENTIFIER "/" IDENTIFIER
- | IDENTIFIER "%" IDENTIFIER
- ;
- /*
- condition: IDENTIFIER EQ IDENTIFIER
- | IDENTIFIER NE IDENTIFIER
- | IDENTIFIER LT IDENTIFIER
- | IDENTIFIER GT IDENTIFIER
- ;*/
- %%
- int main(void){
- // FlexLexer* lexer = new yyFlexLexer;
- // while((lexer->yylex)!=0)
- // ;
- yyparse();
- }
- ---------------------------------
- #!/bin/bash
- clear
- rm launcher lex.yy.cpp *.tab.cpp *.tab.hpp
- bison -d -o lista4.tab.cpp *.y
- flex -o lex.yy.cpp *.l
- g++ -o launcher *.cpp -lfl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement