Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PARSER_BEGIN(Karloff)
- import java.io.*;
- public class Karloff {
- public static void main(String args[]) throws ParseException, IOException {
- Karloff parser = new Karloff(new FileInputStream(args[0]));
- parser.Karloff();
- }
- }
- PARSER_END(Karloff)
- SKIP:{
- " "
- | "\t"
- | "\n"
- | "\r"}
- TOKEN:{
- <MAIN:"main">
- | <ACHAVES:"{">
- | <FCHAVES:"}">
- | <APAREN:"(">
- | <FPAREN:")">
- | <SEMIC:";">
- | <COMMA:",">
- | <FUNC:"func">
- | <TVOID:"void">
- | <NEWVAR:"newVar">
- | <TINT:"int">
- | <TBOOL:"bool">
- | <IF:"if">
- | <THEN:"then">
- | <WHILE:"while">
- | <REPEAT:"repeat">
- | <UNTIL:"until">
- | <RETURN:"return">
- | <TRUE:"true">
- | <FALSE:"false">
- | <OUTPUT:"System.output">
- | <INPUT:"System.input">
- | <PLUS:"+">
- | <MINUS:"-">
- | <ASTERISK:"*">
- | <SLASH:"/">
- | <AMP:"&">
- | <VERBAR:"|">
- | <LESS:"<">
- | <GREATER:">">
- | <ASSIGN:"=">
- | <EQUAL:"==">
- }
- TOKEN:{
- <NUM: (["0"-"9"] | ["1"-"9"] (["0"-"9"])*) ("." (["0"-"9"])* ["1"-"9"])? ("E" (["+","-"])? ["1"-"9"] (["0"-"9"])* )?>
- | <ID: ["a"-"z","A"-"Z"] (("_")?["a"-"z","A"-"Z","0"-"9"])* >
- }
- void Karloff () :
- {Token t;}
- {
- Main() Func() <EOF> {System.out.println("Succesful!");}
- }
- void Main () :
- {}
- {
- <TVOID> <MAIN> <ACHAVES> Vardecl() Seqcomandos() <FCHAVES>
- }
- void Vardecl () :
- {}
- {
- (<NEWVAR> Tipo() <ID> <SEMIC>)*
- }
- void Tipo () :
- {}
- {
- <TBOOL> | <TINT>
- }
- void Seqcomandos () :
- {}
- {
- (Comando() <SEMIC>)*
- }
- void Comando () :
- {}
- {
- <ID> (<ASSIGN> Exp() | <APAREN> ( Listaexp() )? <FPAREN>)
- | <IF> <APAREN> Exp() <FPAREN> <THEN> <ACHAVES> Seqcomandos() <FCHAVES>
- | <WHILE> <APAREN> Exp() <FPAREN> <ACHAVES> Seqcomandos() <FCHAVES>
- | <REPEAT> <ACHAVES> Seqcomandos() <FCHAVES> <UNTIL> <APAREN> Exp() <FPAREN>
- | <RETURN> Exp()
- | <OUTPUT> <APAREN> Exp() <FPAREN>
- | <INPUT> <APAREN> Exp() <FPAREN>
- }
- void Exp () :
- {}
- {
- <APAREN> Exp() Op() Exp() <FPAREN>
- | Fator()
- }
- void Fator () :
- {}
- {
- <ID> ( <APAREN> ( Listaexp() )? <FPAREN> )?
- | <NUM>
- | <TRUE>
- | <FALSE>
- }
- void Op () :
- {}
- {
- <PLUS> | <MINUS> | <ASTERISK> | <SLASH> | <AMP>
- | <VERBAR> | <LESS> | <GREATER> | <ASSIGN> | <EQUAL>
- }
- void Listaexp () :
- {}
- {
- Exp() ( <COMMA> Exp() )*
- }
- void Func () :
- {}
- {
- ( <FUNC> Tipo() <ID> <APAREN> (Listaarg())? <FPAREN> <ACHAVES> Vardecl() Seqcomandos() <FCHAVES> )*
- }
- void Listaarg () :
- {}
- {
- Tipo() <ID> ( <COMMA> Tipo() <ID> )*
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement