Zattara
Zattara

Reputation: 1

How to produce output in C4B in SableCC grammar file

  1. I translated all the tokens in Russian.
  2. Before that, I have set the path in sablecc cmd to java path jdk-20. The program that I want to perform lexical analysis are also in Russian.
  3. But, when I want to perform lexical analysis, the C4B cmd shows that it has error.

This is my decaf code

// decaf.grammar
// SableCC grammar for decaf, a subset of Java in Russian
// March 2003, sdb

Package decaf;

Helpers // Examples
  letter = ['a'..'z'] | ['A'..'Z'] ;             // w
  digit = ['0'..'9'] ;                           // 3
  digits = digit+ ;                 // 2040099
  exp = ['e' + 'E'] ['+' + '-']? digits;         // E-34
  newline = [10 + 13] ;                 // '\n'
  non_star = [[0..0xffff] - '*'] ;               // /
  non_slash = [[0..0xffff] - '/'];               // *
  non_star_slash = [[0..0xffff] - ['*' + '/']];  // $
Tokens
  comment1 = '//' [[0..0xffff]-newline]* newline ;
  comment2 = '/*' non_star* '*'  (non_star_slash non_star* '*'+)* '/' ;
  space = ' ' | 9 | newline ; // 9 = tab
  clas = 'klass' ;              // key words (reserved)
  public = 'publichnyy' ;
  static = 'staticheskiy' ;
  void = 'void' ;
  main = 'glavnyy' ;
  string = 'Stroka' ;
  int = 'tseloye' ;
  float = 'plavayushcheye' ;
  for = 'dlya' ;
  while = 'poka' ;
  if = 'esli' ;
  else = 'inache' ;  
  assign = 'prisvoit' ;
  compare = '==' | '<' | '>' | '<=' | '>=' | '!=' ;
  plus = '+' ;
  minus = '-' ;
  mult = '*' ;
  div = '/' ;
  l_par = '(' ;
  r_par = ')' ;
  l_brace = '{' ;
  r_brace = '}' ;
  l_bracket = '[' ;
  r_bracket = ']' ;
  comma = ',' ;
  semi = ';' ;
  identifier = letter (letter | digit | '_')* ;
  number = (digits '.'? digits? | '.'digits) exp? ;
  misc = [0..0xffff] ;

This is my program

publichnyy klass Main {
    publichnyy staticheskiy void glavnyy(String[] args) {

        tseloye number1 = 10;
        tseloye number2 = 5;
        tseloye result;

        
        result = number1 plus number2;
        Stroka message = "Result of addition: ";
        System.out.println(message plus result);

        
        esli (result > 10) {
            System.out.println("Result is greater than 10");
        } inache {
            System.out.println("Result is not greater than 10");
        }
    }
}

The output that I get in C4B cmd is as below C4B cmd shows error

I've tried to rewrite the program and the lexical tokens too but still can't produce the output.

Upvotes: 0

Views: 14

Answers (0)

Related Questions