Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9032017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:52:38+00:00 2026-06-16T07:52:38+00:00

Need to implement syntax highlighting for COS aka MUMPS for the language of a

  • 0

Need to implement syntax highlighting for COS aka MUMPS
for the language of a possible design of the form

new (new,set,kill)
set kill=new

where: ‘new’ and ‘set’ are commands, and also variable

grammar cos;

Command_KILL            :( ('k'|'K') | ( ('k'|'K')('i'|'I')('l'|'L')('l'|'L') ) ); 
Command_NEW             :( ('n'|'N') | ( ('n'|'N')('e'|'E')('w'|'W') ) ); 
Command_SET             :( ('s'|'S') | ( ('s'|'S')('e'|'E')('t'|'T') ) );


INT : [0-9]+;
ID : [a-zA-Z][a-zA-Z0-9]*;
Space: ' ';
Equal: '=';

newCommand
    :   Command_NEW Space ID
    ;
setCommand
    :   Command_SET Space ID Space*  Equal Space* INT
    ; 

I have a problem, when ID like name as commands (NEW,SET e.t.c.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:52:39+00:00Added an answer on June 16, 2026 at 7:52 am

    According to the Wikipedia page, MUMPS doesn’t have reserved words:

    Reserved words: None. Since MUMPS interprets source code by context, there is no need for reserved words. You may use the names of language commands as variables.

    Lexer rules like Command_KILL function exactly like reserved words: they’re designed to make sure no other token is generated when input "kill" is encountered. So token type Command_KILL will always be produced on "kill", even if it’s intended to be an identifier. You can keep the command lexer rules if you want, but you’ll have to treat them like IDs as well because you just don’t know what "kill" refers to based on the token alone.

    Making a MUMPS implementation in ANTLR means focusing on token usage and context rather than token types. Consider this grammar:

    grammar Example;
    
    
    document    : (expr (EOL|EOF))+;
    expr        : command=ID Space+ value (Space* COMMA Space* value)*  #CallExpr
                | command=ID Space+ name=ID Space* Equal Space* value   #SetExpr
                ;     
    
    value       : ID | INT;
    
    INT         : [0-9]+;
    ID          : [a-zA-Z][a-zA-Z0-9]*;
    Space       : ' ';
    Equal       : '=';
    EOL         : [\r\n]+;
    COMMA       : ',';
    

    Parser rule expr knows when an ID token is a command based on the layout of the entire line.

    • If the input tokens are ID ID, then the input is a CallExpr: the first ID is a command name and the second ID is a regular identifier.
    • If the input tokens are ID ID Equal ID, then the input is a SetExpr: the first ID will be a command (either "set" or something like it), the second ID is the target identifier, and the third ID is the source identifier.

    Here’s a Java test application followed by a test case similar to the one mentioned in your question.

    import java.util.List;
    
    import org.antlr.v4.runtime.ANTLRInputStream;
    import org.antlr.v4.runtime.CommonTokenStream;
    
    public class ExampleTest {
    
        public static void main(String[] args) {
    
            ANTLRInputStream input = new ANTLRInputStream(
                    "new new, set, kill\nset kill = new");
    
            ExampleLexer lexer = new ExampleLexer(input);
    
            ExampleParser parser = new ExampleParser(new CommonTokenStream(lexer));
    
            parser.addParseListener(new ExampleBaseListener() {
                @Override
                public void exitCallExpr(ExampleParser.CallExprContext ctx) {
                    System.out.println("Call:");
                    System.out.printf("\tcommand = %s%n", ctx.command.getText());
                    List<ExampleParser.ValueContext> values = ctx.value();
                    if (values != null) {
                        for (int i = 0, count = values.size(); i < count; ++i) {
                            ExampleParser.ValueContext value = values.get(i);
                            System.out.printf("\targ[%d]  = %s%n", i,
                                    value.getText());
                        }
                    }
                }
    
                @Override
                public void exitSetExpr(ExampleParser.SetExprContext ctx) {
                    System.out.println("Set:");
                    System.out.printf("\tcommand = %s%n", ctx.command.getText());
                    System.out.printf("\tname    = %s%n", ctx.name.getText());
                    System.out.printf("\tvalue   = %s%n", ctx.value().getText());
                }
    
            });
    
            parser.document();
        }
    }
    

    Input

    new new, set, kill
    set kill = new
    

    Output

    Call:
        command = new
        arg[0]  = new
        arg[1]  = set
        arg[2]  = kill
    Set:
        command = set
        name    = kill
        value   = new
    

    It’s up to the calling code to determine whether a command is valid in a given context. The parser can’t reasonably handle this because of MUMPS’s loose approach to commands and identifiers. But it’s not as bad as it may sound: you’ll know which commands function like a call and which function like a set, so you’ll be able to test the input from the Listener that ANTLR produces. In the code above, for example, it would be very easy to test whether “set” was the command passed to exitSetExpr.

    Some MUMPS syntax may be more difficult to process than this, but the general approach will be the same: let the lexer treat commands and identifiers like IDs, and use the parser rules to determine whether an ID refers to a command or an identifier based on the context of the entire line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement some new functions on an editor. I picked Emacs -
I need to implement compiler (lexical, syntax and semantic analyzers). I have already implemented
I need to implement light editor ( recognize part of key words, syntax highlight
I need to implement portable code, but I do not know how to deal
I need to implement an efficient excel-like app. I'm looking for a data structure
I need to implement the following: There is a table A which is supposed
i need to implement the email signature with image.As of now we only support
I need to implement AI for game based on fuzzy logic. I need to
I need to implement a simple monitoring app in Excel. It is for monitoring
I need to implement a thread pool in Java (java.util.concurrent) whose number of threads

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.